-
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
Android P has more socket timeouts #3974
Comments
same issues , use okhttp 3.7.0 |
ok will upgrade and verify |
maybe the server problem |
as soon as connected to wifi it works, so server is not a issue, it comes randomly however when problem start coming then even after trying 100 times it get timeout but as soon as connectivity changes or mobile reboot then it works. |
Even if the server or network is causing issues, this Exception should be handled somewhere and passed to listeners instead of crashing the whole thread. I've seen many people suggest to increase the timeouts as a fix, but it's only a workaround. I want my requests to time out in a reasonable amount of time, but I want to be able to handle the error. |
Stack traces of related timeout errors:
and
|
OkHttp notifies you with an exception on |
@swankjesse That's strange. I'm pretty sure I'm catching this type of Exception everywhere and yet I receive crash reports like the ones above. I've spent several hours on making sure I'm handling it everywhere, but maybe I'm still missing a |
These are async calls. You're handling them in onFailure? |
I use OkHttp in two ways: Directly with coroutines and using Retrofit's Direct usage works like this: override fun onFailure(call: Call, e: IOException) {
// Don't bother with resuming the continuation if it is already cancelled.
if (continuation.isCancelled) return
continuation.resumeWithException(e)
} I suppose Retrofit does it similarly. In both ways I then just use try-catch as I would in plain old procedural code, handling any Thanks for your help! |
Not sure but is it linked with any static variable declare some where.
Because in our case we do have some large file upload in another thread and
that gets timeout sometime.
As soon as we switch of net and restart in 5-10 minutes then everything
start working fine.
Harish
…On Fri, May 4, 2018, 20:36 Yuri Schimke ***@***.***> wrote:
We should handle this, it's not an IOException
public class SocketTimeoutException extends java.io.InterruptedIOException
{
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3974 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AkvlmEOwvf7PegLWrT5_8TYwMaa_3LxGks5tvG6DgaJpZM4Tbo6O>
.
|
okhttp-3.8.0 same problem: .onFailure(UploadIntentService.java:72) timeout |
the same in 3.10.0 |
@swankjesse |
@swankjesse okhttp 3.10.0 Bug 2: |
That's great I hope team will be able to fix this quick
Regards
Harish
…On Mon, Jun 11, 2018, 18:33 jacky_z ***@***.***> wrote:
@swankjesse <https://github.com/swankjesse> okhttp 3.10.0
Hello, I find two problems here.
It looks like problem 1 caused by problem 2.
This is the Socket Timeout Error which in my monitor data. It happend
about 400000.
I hope to receive your feedback
thanks!
Bug 1:
at okio.Okio$4.newTimeoutException(Okio.java:232)
at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
at
okhttp3.internal.http1.Http1Codec$AbstractSource.read(Http1Codec.java:363)
at
okhttp3.internal.http1.Http1Codec$UnknownLengthSource.read(Http1Codec.java:507)
at okio.Buffer.writeAll(Buffer.java:1053)
at okio.RealBufferedSource.readString(RealBufferedSource.java:200)
at okhttp3.ResponseBody.string(ResponseBody.java:175)
at com.jd.JDResponse.(JDResponse.java:33)
at com.jd..net.core.HttpCore$2.onResponse(HttpCore.java:188)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.read(SocketInputStream.java:203)
at java.net.SocketInputStream.read(SocketInputStream.java:139)
at okio.Okio$2.read(Okio.java:140)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
... 13 more
Bug 2:
okio.RealBufferedSource.rangeEquals (RealBufferedSource.java:377)
okio.RealBufferedSource.rangeEquals (RealBufferedSource.java:371)
okhttp3.internal.Util.bomAwareCharset (Util.java:397)
okhttp3.ResponseBody.string (ResponseBody.java:173)
com.jd.JDResponse. (JDResponse.java:23)
com.jd.net.core.HttpCore$2.onResponse (HttpCore.java:175)
okhttp3.RealCall$AsyncCall.execute (RealCall.java:135)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32)
java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:587)
java.lang.Thread.run (Thread.java:818)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3974 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AkvlmOQBeOIDKNYS6kWALJ3cNYNpiR30ks5t7mqvgaJpZM4Tbo6O>
.
|
I have same issue only on Android 7 & 8 okhttp 3.10.0. After wifi restart or connect to the mobile data problem is resolved by itself. |
same issue |
sounds similar to my issue: I often see timeout errors after unlocking my screen. if I have my app open, turn off the screen, stick phone in pocket for a couple of minutes, take phone out of pocket and turn on screen, my app triggers a couple of net requests during onResume, I then often but not always see a few timeouts. |
Any update or workaround solution available for this issue? |
My server uses nginx 1.10.0 and supports HTTP2. I disabled HTTP2 in OkHttp and for now app is working. I'm not sure but maybe it is solution for me: @putuyuwono @steelbytes @hkachoria @7280423 @lizhangqu @cbruegg @Warpath |
@askarsyzdykov both HTTP/1.1 and HTTP/2.0 have this problem. I have do an A/B Test for this. the timeout exception don't seem to change. |
I met the same problem : java.net. SocketTimeoutException, |
I'm having this problem too.. When I switch networks (cellular to WIFI) it works for a while (sometimes some minutes, sometimes for hours) then starts giving the TimeoutException.. Also if I open Chrome and make the GET request I get the answer immediately without problem but if I switch back to my app using OkHttp I keep getting timeouts... |
I have a similar error. Restarting a device fixes the problem. It usually happens when I execute multi-threaded downloads. java.net.SocketTimeoutException: timeout |
I've found a way to reproduce this, though I'm not entirely sure that this is what our customers are hitting. I've been able to trigger this on Android 7.1.2, and Android P r3 using these steps: https://developer.android.com/training/monitoring-device-state/doze-standby
Launch your app now, and I get the socket timeouts. I would point out that this doesn't seem to be 100% of how to reproduce this, as I couldn't get this to work across all my test devices. Interestingly, we do check with the On a Samsung running android 8.0.0 I was unable to reproduce this using these steps atll. Even if I never issue the |
@inktomi I reproduce the problem in your way. |
BTW the code I have looks at both (background/foreground events) and per network events (e.g. wifi available, cell connection is scheduled to stop in 30 seconds). The optimal result is probably some combination of these. But if you look at this comment (#3974 (comment)) note it's Android 9 and only in background. So that would be the minimal fix (version >= 9 && backgrounded && app not allowed background connectivity). So should I start off with a broad fix enabled by registering the Context (so we can grab services) with the Android Platform? This would be an android specific API inside a new module. |
Is the ultimate decision this thing makes to choose connections from the pool? I think I'm overdue on my promise to offer pluggable policies on the connection pool, which potentially ties into this also. |
@yschimke Majority of it is on Android 9 but this is affecting almost all Android versions. |
Not IIUC. My understanding is that on Android P, your app probably can't do IO when in the background. But things might recover when the app is foregrounded again. I can start with this and see if it solves this specific problems. As well as this Android exposes events for each network and controls these based on it's own policies. So you can also model networks (id, name, local ip address, per network proxies, availability events, cost). You could just switch networks so new streams don't reuse a connection that Android wants to reclaim, you use the preferred network. Or allow users to send corp requests only over Wifi. Background Video requests only when it's really Wifi etc. I think ultimately having visibility of what is going on will also allow us to understand and model it correctly, allow developers to make better decisions of how to use the network and when. |
@prempalsingh Thanks, that's useful. I guess than I'm really talking about the word more in the issue description. |
Seem like facebook use okhttp too so I would like to drop my log here
|
@Thaina They use |
We also have this issue, we could reproduce it in the following devices:
Reproduction steps Enable battery save mode.
|
java.net.SocketTimeoutException: failed to connect to xxx/2409:8c54:b000:701:1c5:991a:1136:b4a (port 443) from /2409:8962:50a:4b84:85b4:4615:39e8:211e (port 58414) after 10000ms We also face the same problem, use chrome open the url it's ok, but okhttp always timeout. Okhttp 4.9.0 |
@crossle @iliaskomp is it eventually getting back to a healthy state (expected) after a cluster of failed requests? Or is it staying unhealthy? |
It' back to healthy state. |
Hello, could you please tell me if there is any conclusion about huawei mobile phone connection timeout? I also found similar feedback. All of them were Huawei phones, also java.net.SocketTimeoutException: failed to connect to. |
Hi, I am still getting socket timeouts on Android 11, also timeouts are still present on older android versions. |
hello, I have encountered the same problem. Do you have a conclusion? Thanks! |
|
Do we have any update about this issue. Facing Socket timeout in Android 12 version as well. Do we have any temporary work around. |
I found a workaround solution for this issue.
|
This works with Web socket and HTTP/2 only. So if you use HTTP/1, this setting is not used. |
I added observability to compare the difference in number of SocketTimeoutExceptions when 3 seconds ping interval is enabled and disabled. It looks promising.
I didn't notice any problems with the app after adding ping interval. Users don't report any new issues. |
Thanks for that detail results. One thing to consider is that this ping likely keeps the radio on a lot more. So there is a battery cost, maybe can be offset but closing open connections sooner? But the results do look much better. |
Do we know what the actual issue is here? There is another thread that discusses socket timeout exceptions with respect to changing network status (offline back to online), but that doesn't seem to be the issue here. I'm also experiencing this on an array of devices. I'll try out the ping fix. Stack trace:
|
Hello, have you worked out this issue? |
Bug reproduced on emulator Nexus S SDK 29, okhttp3 4.9.3 (also 5.0.0-alpha.7).
Using ConnectionPool with maxIdleConnections 0 solves the problem. |
I also face the same issue. java.net.SocketTimeoutException: timeout But from server we can see that the request is successful. Very strange. |
Seems likely a dupe of #3278, since comments related to turning internet off and on |
OKHttp version - 3.4.2
on Android
Some time our client is facing timeout exception.
Server is available, that we verified using some other service.
Problem only come for post request, Timeout increased to 200 seconds still problem exists.
We debug on server as well and noticed that request not reaching to server, network connectivity is not issue as some other service with get request works well at same time.
Client code -
OkHttpClient client = new OkHttpClient.Builder().connectTimeout(200, TimeUnit.SECONDS).
readTimeout(200, TimeUnit.SECONDS)
.writeTimeout(200, TimeUnit.SECONDS)
.followRedirects(true)
.followSslRedirects(true)
.build();
Exception -
Caused by: java.net.SocketTimeoutException: timeout
at okio.Okio$4.newTimeoutException(Okio.java:227)
at okio.AsyncTimeout.exit(AsyncTimeout.java:284)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:240)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:325)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:314)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:210)
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:53)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.execute(RealCall.java:60)
at com.mexel.prx.util.general.HttpUtils.postInternal(HttpUtils.java:329)
... 8 more
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:151)
at java.net.SocketInputStream.read(SocketInputStream.java:120)
at okio.Okio$2.read(Okio.java:138)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:236)
The text was updated successfully, but these errors were encountered: