4

In the simplest case, when I have a KeyPair key for an account that doesn't yet exist, and call

// private Server mServer; // declared and intialized elsewhere
mServer.accounts().account(key);

it throws an HttpResponseException, but each time it runs, the system's thread count (returned by Thread.activeCount()) goes up by 2. I've tried modifying handleResponse() (in org.stellar.sdk.requests.ResponseHandler.java) to call close() on the response before throwing, but to no avail.

Is there some way I can free those threads after the exception's thrown, or does the OkHttp client code in the SDK need to be changed?

1 Answer 1

3

Against version 0.2.0 with Java 8 I have run:

public static void main(String[] args) throws Exception {

    String clientPk = "GBKVT7EO462QUCQVBNBWI47J6NQ6UKQUXLJOAWC7ZSIZKATMIDTK32X6";

    Server server = new Server("https://horizon-testnet.stellar.org");

    KeyPair destination = KeyPair.fromAccountId(clientPk);

    while (true) {
        try {
            server.accounts().account(destination);
        } catch (ErrorResponse e) {
            System.out.println(e.getBody());
            System.out.println("Thread.activeCount() = " + Thread.activeCount());
        }
    }
}

The thread count did not increase.

{
  "type": "https://stellar.org/horizon-errors/not_found",
  "title": "Resource Missing",
  "status": 404,
  "detail": "The resource at the url requested was not found.  This is usually occurs for one of two reasons:  The url requested is not valid, or no data in our database could be found with the parameters provided."
}
Thread.activeCount() = 4
{
  "type": "https://stellar.org/horizon-errors/not_found",
  "title": "Resource Missing",
  "status": 404,
  "detail": "The resource at the url requested was not found.  This is usually occurs for one of two reasons:  The url requested is not valid, or no data in our database could be found with the parameters provided."
}
Thread.activeCount() = 4
{
  "type": "https://stellar.org/horizon-errors/not_found",
  "title": "Resource Missing",
  "status": 404,
  "detail": "The resource at the url requested was not found.  This is usually occurs for one of two reasons:  The url requested is not valid, or no data in our database could be found with the parameters provided."
}
Thread.activeCount() = 4
... forever

I do not get an HttpResponseException. The exception thrown is org.stellar.sdk.requests.ErrorResponse. Perhaps you are configuring your server differently.

1
  • Ha -- thanks! I'm running on android using android-stellar-sdk-kin which is derived from an older release of java-stellar-sdk. When I rebuilt it with the 0.2.0 sources of java-stellar-sdk the problem went away.
    – eehouse
    Commented Apr 19, 2018 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.