-
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
Network calls hang after coming back online after being offline #3278
Comments
Thanks for putting together the sample app. If you have any insight into how OkHttp could reliably detect this situation, that’d be handy. |
I don't, unfortunately. The only thing I can think of is some kind of reachability test, but that seems expensive. |
Basing on this example i make some test and:
This is my observation, I hope this helps |
Setting "keepAliveDuration" also has an impact on this. |
Had a quick look at this with OkHttp 3.9.0 A few comments:
One option might be to support platform reachability services, specifically on Android, and test connections after reachability events before handing them out. |
Tagging as enhancement - I think since this is so easily reproducible even on Android 8 with OkHttp 3.9.0, that detecting this cleanly and making it work will be relatively high impact. n.b. I couldn't get into the permanent http/2 failure state that @kenumir saw, so maybe that is fixed. |
not fixed to me, Im using okhttp3.10 with emulator on android api 27 and just after go back online (turn airplane mode off) at first request the the timeout error come out, but after first request everything works |
I had the same issue on emulator and some samsung devices.
It might be due to how HTTP/2 connections established and maintained at OS level on these devices. |
Hey guys, I thought this was supposed to be fixed here #3261, but I ran @arstk8's sample (https://github.com/arstk8/TestEsriNetworkCall/) with okhttp 3.12.3 and sdk 26, the issue seems to persist. @minobilis I've also tried your workaround by changing on MainActivity.java:34 Apparently the issue presents itself only on Android emulators. Is there any fix on sight that could be done? Thanks in advance!! |
Probably worth retesting after #5920 which is in 4.5, I'm hopeful that fixes a ton of connectivity issues with dodgy Android networking. |
I think I am still seeing this with OkHttp 4.9.1 on Android 9/10. It is critical for me. This is a thread dump of the connection thread in question:
Is that the same issue or a different one? Now trying to limit the protocol used to I have the client configured like this:
|
Limiting Protocol to HTTP/1.1 did not help much. The exact same issues still occurs. This bug is especially easy to notice when restricting the ConnectionPool to 1 idle connection (as then all HTTP requests will hang when the issue occurs). Ideas: |
When I use callStart(302619159)->proxySelectStart(302619209)->withRequestStart(302619210)->proxySelectEnd(302619210)->dnsStart(302619210)->proxySelectStart(302619221)->withRequestStart(302619221)->proxySelectEnd(302619222)->dnsStart(302619222)->dnsEnd(302619234)->connectStart(302619237)->connectFailed(302639262)->connectStart(302639264)->connectFailed(302647219)->proxySelectStart(302647264)->withRequestStart(302647264)->proxySelectEnd(302647265)->dnsStart(302647265)->proxySelectStart(302647275)->withRequestStart(302647275)->proxySelectEnd(302647275)->dnsStart(302647275)->dnsEnd(302647284)->connectStart(302647285)->connectFailed(304721621)->canceled(304721622)->withRequestEnd(304721622)->callFailed(304721639)->withRequestEnd(304721639) The problem fragment is OKHttpClient Setting:
Other Info:
Is this the same problem mentioned in this issue? |
It sounds at least somewhat related. It's been some time, but IIRC the problem is that in certain situations the HTTP library really can't do much as it doesn't receive a timely response from the OS. Some active watcher thread/timer and more complicated logic would be required. |
The other approach which we haven't wanted to get into, is to subscribe to android network changes. |
We still have this issue with version I tried to listen to the network state and call The exception I am getting after the call timeout is:
|
I think that I found out what is actually happening on emulators (but not only on them)! After trying out many things, I added a delay between reconnecting to the network and sending the first request. I ended up at ~2 seconds. Then I noticed that this is the time in which the emulator usually connects to the wifi (!) network after airplane mode. With the delay, it worked perfectly fine. Now let's have a look at what is happening without the delay (make sure cellular network and wifi are enabled, this is the default on emulators):
I assume that the network request was (sometimes) fired exactly in the timeframe between 3G being connected and wifi being connected. After the call was fired to the 3G network connection it just timed out as the emulator killed that interface (?) when switching over to wifi. The response from the server was sent but never reached the client through the 3G connection as is might only be ready to receive data over wifi. This never happened on my Pixel phone during testing as wifi is still turned on in airplane mode on these devices. Samsung for example behaves the same as the emulator and turns on cellular first before it switched to wifi to this issue is also reproducible on these devices. @swankjesse @yschimke I hope this helps to understand the actual issue here. Is there something that you could change inside OkHttp in this case? |
I am facing the same issue with Android 10 devices |
I have an interesting issue I'm seeing with okhttp, but so far I can only reproduce it on Android emulators (default Android emulator and Genymotion)
If I make a bunch of requests to the same server (enough to saturate the connection pool) and then go offline (airplane mode) and then come back online, any subsequent requests I make to that server hang until one of the connections in the connection pool is removed after 5 minutes of inactivity.
I'm not sure if the emulator thing is a timing issue (emulators execute faster in my experience) or if it's a quirk with the networking configuration vs a real device. The fact that it happens on more than one type of emulator seems significant to me.
I have a sample app which reproduces it here: https://github.com/arstk8/TestEsriNetworkCall/
I know you're preferred way to reproduce is via MockWebserver test case, but I can't figure out a way to reproduce it that way.
The text was updated successfully, but these errors were encountered: