Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketTimeoutException: Read timed out when executing HTTPS requests #146

Closed
wonderfly opened this issue Jan 9, 2015 · 27 comments
Closed
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@wonderfly
Copy link
Contributor

From ma...@onlulu.com on July 31, 2012 09:43:21

Version of google-http-java-client (e.g. 1.5.0-beta)? 1.10.3 Beta Java environment (e.g. Java 6, Android 2.3, App Engine)? Android 4.1 (Google Nexus) Describe the problem. I'm using an HttpTransport got with AndroidHttp.newCompatibleTransport() to perform multiple requests to a server using the HTTPS protocol. Both using WiFi and 3G, I sometimes get this exception when executing a request:

07-31 17:14:40.659: W/System.err(7558): java.net.SocketTimeoutException: Read timed out
07-31 17:14:40.659: W/System.err(7558): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
07-31 17:14:40.659: W/System.err(7558): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:675)
07-31 17:14:40.659: W/System.err(7558): at libcore.io.Streams.readSingleByte(Streams.java:41)
07-31 17:14:40.659: W/System.err(7558): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:659)
07-31 17:14:40.659: W/System.err(7558): at libcore.io.Streams.readAsciiLine(Streams.java:201)
07-31 17:14:40.659: W/System.err(7558): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
07-31 17:14:40.659: W/System.err(7558): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
07-31 17:14:40.659: W/System.err(7558): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
07-31 17:14:40.659: W/System.err(7558): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
07-31 17:14:40.659: W/System.err(7558): at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
07-31 17:14:40.659: W/System.err(7558): at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:37)
07-31 17:14:40.667: W/System.err(7558): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:91)
07-31 17:14:40.667: W/System.err(7558): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:895)

Note that:

  • Other HTTP requests complete normally in the meantime.
  • My connection and read timeouts are set respectively to 10 and 20 seconds.

There are other users experiencing this issue with the error reporting library ACRA, which might use google-http-java-client as well. This is the link to the issue: https://code.google.com/p/acra/issues/detail?id=128 How would you expect it to be fixed? No idea, I don't even know if it's a library or system issue.

Original issue: http://code.google.com/p/google-http-java-client/issues/detail?id=146

@wonderfly wonderfly added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. imported priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 9, 2015
@wonderfly wonderfly self-assigned this Jan 9, 2015
@wonderfly
Copy link
Contributor Author

From craig.we...@gmail.com on September 06, 2012 01:49:14

I'm also experiencing this problem, the requests over HTTP consistently work whereas the requests over HTTPS are intermittently faulty, they come back with a timeout exception:

09-06 10:39:19.326: E/(6394): java.net.SocketTimeoutException: Read timed out
09-06 10:39:19.326: E/(6394): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
09-06 10:39:19.326: E/(6394): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:801)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
09-06 10:39:19.326: E/(6394): at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
09-06 10:39:19.326: E/(6394): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-06 10:39:19.326: E/(6394): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-06 10:39:19.326: E/(6394): at za.co.itdynamics.stockcount.mobileu_server.MobileuServerInterface.getSyncPriorityForApplicationVersion(MobileuServerInterface.java:80)
09-06 10:39:19.326: E/(6394): at za.co.itdynamics.stockcount.list.StockCountListActivity$5.run(StockCountListActivity.java:390)

@wonderfly
Copy link
Contributor Author

From ma...@onlulu.com on October 01, 2012 08:07:02

Any news on this? Unfortunately the issue prevents me from using the google-http-java-client at all..

@wonderfly
Copy link
Contributor Author

From yan...@google.com on October 01, 2012 18:42:57

Please try setting the read/connect timeout. There is an example here based on the Google API library, but it generalizes to any HttpTransport when calling createRequestFactory with the HttpRequestInitializer: https://code.google.com/p/google-api-java-client/wiki/FAQ#How_to_set_read/connect_timeouts_using_the_generated_libraries

Status: RequestedFeedback
Owner: yan...@google.com
Cc: rmis...@google.com

@wonderfly
Copy link
Contributor Author

From emmanuel.rodriguez on October 02, 2012 06:09:13

My app has the same problems. All http request that are done by the app are through SSL (HTTPS only) and I see this timeouts happening all the time.

Increasing the socket timeouts make things worse because the app seems to be not responding as it's waiting for the timeout. Something strange is going on when creating the HTTPS connection.

@wonderfly
Copy link
Contributor Author

From atereshc...@stanfy.com.ua on October 02, 2012 06:28:20

We've ported our API from ApacheHttpClient to URLConnection and now struggling with the same timeouts. I think it's not a google-http-java-client issue or java.net.HttpURLConnection but it could be a broken implementation of org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read() in Android 4.1

@wonderfly
Copy link
Contributor Author

From ma...@onlulu.com on October 02, 2012 10:03:47

I forgot to mention, but I was already setting large timeouts trying to avoid the issue but, as emmanuel.rodriguez pointed out, this is only getting things worst.

Is there any open issue in Android for this?

@wonderfly
Copy link
Contributor Author

From b...@google.com on October 02, 2012 10:17:27

Hello, you've reached the maintainer of SSL in Android. Both ApacheHttpClient and URLConnection should use the same OpenSSLSocketImpl implementation class by default (which calls NativeCrypto.SSL_read(). It is possible that a non-default SSLSocketFactory can be used, leading to the slower non-OpenSSL SSLSocketImpl to be used. I would use strace to verify what socket options are being set for timeout.

@wonderfly
Copy link
Contributor Author

From riv...@gmail.com on October 02, 2012 11:00:43

I've noticed that this is pure Android 4.1 problem - actually we've tested on Galaxy Tab, Nexus 7 and Asus Transformer and this issue exists only on Nexus.

P.S. I could provide any additional logs needed.

@wonderfly
Copy link
Contributor Author

From b...@google.com on October 02, 2012 12:12:35

I don't know what the google-http-java-client maintainers would like, but if there was a "public static void main(String args[])" style test case .java file, I can try running it to see what the issue is.

@wonderfly
Copy link
Contributor Author

From emmanuel.rodriguez on October 03, 2012 08:01:15

At comment #7 how can I run strace in my phone? The executable is not available in my phone (Galaxy Nexus running stock Jelly Bean 4.1.1).

@wonderfly
Copy link
Contributor Author

From b...@google.com on October 03, 2012 11:18:24

It is in the emulator if you can reproduce there, or if you can copy the binary over from there.

@wonderfly
Copy link
Contributor Author

From ma...@onlulu.com on November 20, 2012 02:35:20

Still experiencing this issue on google-http-java-client 1.12.0.
I guess it's an Android library issue, anyway.

@wonderfly
Copy link
Contributor Author

From ivan.mas...@gmail.com on November 27, 2013 07:22:02

hello all,
I have the same issue using HttpsUrlConnection on Samsung galaxy tab 7.0 plus and android 4.1.2. Have someone found a solution on this issue?

@wonderfly
Copy link
Contributor Author

From riv...@gmail.com on November 27, 2013 07:35:35

We've found that it generally problem of WiFi connection (WiFi router, gateway etc).
Both Android and iOS devices had problems with request timeout using HTTPS.
So i'd advise you to test mobile network first.

@wonderfly
Copy link
Contributor Author

From tapas.mo...@gmail.com on April 25, 2014 13:11:31

hi, I am facing the same issue in my mobile network only. I am using 2G connection .It is working fine in normal http protocol.

@wonderfly
Copy link
Contributor Author

From ssymbol....@gmail.com on May 18, 2014 05:06:03

Did anything change? Was the problems resolved?

@wonderfly
Copy link
Contributor Author

From ssymbol....@gmail.com on May 18, 2014 05:06:56

I am using Android App Engine connected project and facing the same issue. I would be ahappy to get any solution

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on May 19, 2014 05:10:43

Cc: -rmis...@google.com

@wonderfly
Copy link
Contributor Author

From leo.qui...@gmail.com on July 19, 2014 04:09:33

I also have this issue. Seeing this both on a phone (wifi), and on the emulator

java.net.SocketTimeoutException: Read timed out
at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:689)
at java.io.InputStream.read(InputStream.java:162)
at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
at java.io.BufferedInputStream.read(BufferedInputStream.java:227)
at com.android.okhttp.internal.Util.readAsciiLine(Util.java:316)
at com.android.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:308)
at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:135)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:644)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136)
at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:36)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
at com.synapticstuff.nofomo.requests.ApiRequest.loadDataFromNetwork(ApiRequest.java:52)
at com.octo.android.robospice.request.CachedSpiceRequest.loadDataFromNetwork(CachedSpiceRequest.java:45)
at com.octo.android.robospice.request.DefaultRequestRunner.processRequest(DefaultRequestRunner.java:149)
at com.octo.android.robospice.request.DefaultRequestRunner$1.run(DefaultRequestRunner.java:216)
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)

@wonderfly
Copy link
Contributor Author

From petar.pe...@gmail.com on November 04, 2014 04:05:38

We have the same issue in production. Timeouts (CONN & SO_TIMEOUT) are set to 30 sec. This is currently happening on the following devices:

samsung SM-N9005 / 4.4.2
samsung GT-I9506 / 4.3
samsung GT-I9295 / 4.4.2
samsung GT-I9515 / 4.4.2 (SSL handshake timed out)
samsung SGH-M919 / 4.4.4 (Read error: ssl=0x77c07030: I/O error during system call, Connection timed out)

@wonderfly
Copy link
Contributor Author

From andreike...@gmail.com on December 08, 2014 07:53:40

Hello petar,

Have you found a solution to the problem?? I'm having the same issue to model GT-I9515 and another devices too.

java.net.SocketTimeoutException: Read timed out
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:670)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
at com.newrelic.agent.android.instrumentation.HttpInstrumentation.execute(HttpInstrumentation.java:117)

@wonderfly
Copy link
Contributor Author

From riv...@gmail.com on December 08, 2014 11:05:12

I'm gonna repeat what was said - try different routers and see if problem occurs.
I've had this error for all devices (including iOS), but only on particular WiFi hotspot

@wonderfly
Copy link
Contributor Author

From petar.pe...@gmail.com on December 08, 2014 12:33:53

I'm gonna repeat what was said - try different routers and see if problem occurs.

Sadly, that would not be feasible at our side. We've got hunderds of devices all around the world. :(

@andreike: I found no solution to this but on the other side there were no explicit customer complaints about it. I assume it happens when the customer/app user switches between WiFi/3G in the middle of a request being processed. For now, we have just disabled the error reporting (for this exception types only) and redesigned parts of our app around this issue (repeat request, graceful error handling, etc.)

More feedback would be appreciated though.

@msangel
Copy link

msangel commented May 3, 2017

So if we will use google-http-java-client sameversion as Android 7.1(or above) , in our projects, then we will be free of this bug?

@notdang
Copy link

notdang commented Oct 16, 2017

I am seeing something similar, can someone else check the certificates and let me know if those certificates are also issued by Letsencrypt ?

My theory is that the JDK/JRE contains neither the Let's Encrypt CA specifically nor the IdenTrust CA that cross signed it.

@jackyq2015
Copy link

jackyq2015 commented May 29, 2018

Any fix for this?

I am using Linux 18.0.4 and Java 8. have the same issue, 20 seconds timeout for reading a sheet. Seems the way suggested by google is not working:

            public void initialize(HttpRequest httpRequest) throws IOException {
                credential.initialize(httpRequest);
                httpRequest.setConnectTimeout(3 * 60000);  // 3 minutes connect timeout
                httpRequest.setReadTimeout(3 * 60000);  // 3 minutes read timeout
            }

The code is hosted on github.

@thehesiod
Copy link

we just started seeing large consistent socket read timeouts with the python client with a timeout of 15s. Interestingly this was prefixed with rate limiter errors. I'm wondering if they're banning IPs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants