1

I've done long search before doing this post and I've done many test but without success.

My Problem (in short): with 3g data connection, every time I do a get request, the first time the connection complete with success.

Now, if the device go in standby for few minuts, when I repeat the same get request it fails istantly with the error that I've reported below. Some comments:

  1. I'm having this issue only with a Rooted Nexus 5 (Android 4.4.2)
  2. If the device don't go in standby, I can't reproduce the problem
  3. If I try a third time, the connection complete with success.
  4. In WiFi mode I can't reproduce the problem.
  5. Tested also with Galaxy S3 (android 4.3) and Galaxy S1 and can't reproduce the problem.
  6. I'm using last version of Loopj AsyncHttpClient libray (1.4.4) found here: http://loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpClient.html

ERROR DETAIL

javax.net.ssl.SSLException: Read error: ssl=0x75cab460: I/O error during system call,   
Connection reset by peer
at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:689)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:74)
at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:91)
at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

Response body is null, calling onFailure(Throwable, JSONObject)

Let's see some code.

I have a singleton class where I manage all connections:

...
//Static istance of my httpClient
private static AsyncHttpClient client = new AsyncHttpClient();
//This is the only parameter that I'm setting for the client
client.setTimeout(30000);
...

//When i need to a get request I just use the following code.
client.get(mContext, url, params, responseHandler);

//For testing purpose, before doing any get request, I've done a clear of all requests,
//but this is not helping with my problem.
client.cancelRequests(mContext, true);

I'm lost now: I don't know if I am missing some configuration parameters on the client, or if the client is trying to reuse a wrong connection, etc...

I'm a new user of the library, so I can really be doing something wrong.

I hope someone can help me.

Thanks in advance.

morten.c
  • 3,414
  • 5
  • 40
  • 45
Danno
  • 93
  • 2
  • 9

1 Answers1

0

Sometimes it would happen to me that Android clears objects contained in static classes (in your case, that singleton). It could be that this error is not about your 3g connection but about memory managment. So the best thing would be to create a method that returns your client.

public static void getClient(){
    if(MySingleton.client == null){
        MySingleton.client = new AsyncHttpClient();
    }

    return client;
}

I gave you an example here, you should do it with all objects you are saving in your singleton.

Android is tricky when you have an app that uses a lot of memory and use a singleton, even if you extend Application class it can garbage collect objects in Application singleton.

Drag0
  • 8,438
  • 9
  • 40
  • 52