-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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 on Retrofit 1.9.0 + OkHttp 2.3.0 + Android 4.4.4 #1771
Comments
Is this a bug or a legitimate timeout? Could you provide an executable test case that demonstrates the problem? There are a few tests in |
Sorry, I can't write that test case. It only appeared on that device.
|
Related issue: This can fix it:
|
Hopefully this fixes it with Okio 1.6.0: square/okio#164 |
Nice, fixed! |
Still experience the issue with the following setup in build.gradle: android:vmSafeMode="true" didn't fix the issue |
Still happens in okhttp 2.5.0 on my Lollipop device. |
You don't need to comment on every issue. On Thu, Oct 22, 2015 at 4:15 PM Igor Ganapolsky notifications@github.com
|
It's annoying. Those subscribed to these projects don't need to get 4 On Thu, Oct 22, 2015 at 4:19 PM Igor Ganapolsky notifications@github.com
|
This is still happening. I am using Retrofit 1.9.0 with OkHttp 2.6.0. retrofit.RetrofitError
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.net.SocketTimeoutException
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:79)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:909)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:93)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:894)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:748)
at com.squareup.okhttp.Call.getResponse(Call.java:277)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:234)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:196)
at com.squareup.okhttp.Call.execute(Call.java:79)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
... 7 more My guess is that this issue is related to dead sockets. Server closes connections and client has no way to figure out that the socket is closed. OkHttp writes to the socket, and tries to read from it, hence the I am experiencing this a lot on a LG G2 device. After this a number of connections fails and after about a minute or two, it starts to work. (Maybe all the sockets in the pool are closed and renewed?). I used OkHttp 2.4 and 2.5, too. This issue is with me for about 6 months! |
@mblcdr What TLS version is your server using? |
@IgorGanapolsky I suppose it is version 1. TLSv1/SSLv3. |
Well I had the same problem with TLSv1.0. So that could be the root cause. On Thu, Dec 3, 2015 at 4:57 PM, Hamid Moazzami notifications@github.com
|
@IgorGanapolsky Well, I don't think that's the problem. We have a test server with no ssl, and the issue is present there, too. |
I'm also experiencing SocketTimeoutExceptions on read using OkClient. I haven't (but will try) UrlConnectionClient. No SSL on the server. We were unable to reproduce the problem with a separate API test client (not Android). Server is returning successful responses quickly so I'm not sure why the read hangs for so long (and eventually times out).
|
I think this issue needs to be reopened. |
I switched to UrlConnectionClient() a few days ago. The socket timeouts have been less frequent, but do occur. Is it possible that the problem (if there is one) may not be client related but something lower level? java.net.SocketTimeoutException |
@mblcdr thanks for the references. Is there anything I can do to determine if my issue is related to connection leaking? |
@bdiegel |
UPDATE: my issue appears to be between with this particular device (Nexus 5- 6.0) and my 5 GHz WiFi (real timeouts). I have a dual band router and have no issue when connected to the 2.4. Also, another Nexus 5 - 6.0 works just fine on the same 5G. Suppose it may have different WiFi hardware (did not confirm). I tried a few other devices now and they work fine also. I'll be updating to 6.0.1 next and will see if that fixes anything for this device. Cheers! |
I get the same exception. In my case, I turn on the airplane mode and then turn it off, and I get the timeout error. using okhttp 2.7.0 on android 6.0.0 Nexus 5x x86 Emulator Update: Just tested it my code on an actual device Motorola Moto X pure edition Marshmallow 6.0.0 and all looks good. |
Hi guyz how can i use synchronous connection suing retrofit android |
I solved that problem increasing writeTimeout.
|
I'm still experiencing the same issue with Retrofit 2.1.0 and OkHttp 3.3.0 |
Same here, issue still present. |
mark |
it's wired, when i use vpn on android device, it will be connect to the server and can send request and receive response but if i switch off vpn, all requests will be |
I face with the same problem. Have yout fixed it? |
@moshtagh i used caddy web server as reverse proxy and put my web service api behind that. |
Same error with com.squareup.retrofit2:retrofit:2.5.0 `private static OkHttpClient getNewHttpClient(int connectionTimeoutSec, int readTimeoutSec, int writeTimeoutSec) {
|
I'm using Retrofit 1.9.0 + OkHttp 2.3.0 + okhttp-urlconnection 2.3.0.
It works well on most android devices, but one Android 4.4.4 KTU840 phone (xiaomi - MI 4LTE).
The
SocketTimeoutException
often appear after one or more service calls.Whenever the exception appeared, no more request can work well, I have to restart the application.
Is it a known bug?
When I remove
okhttp-urlconnection
and setup timeout ofokhttp
client, no help to solve it.When I use
UrlConnectionClient
(provided by retrofit) instead ofOkClient
, it works well.Sorry for my bad english!
Output of logcat:
My code:
The text was updated successfully, but these errors were encountered: