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:
- I'm having this issue only with a Rooted Nexus 5 (Android 4.4.2)
- If the device don't go in standby, I can't reproduce the problem
- If I try a third time, the connection complete with success.
- In WiFi mode I can't reproduce the problem.
- Tested also with Galaxy S3 (android 4.3) and Galaxy S1 and can't reproduce the problem.
- 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.