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

Incorrect retries on connection that still succeeded #8587

Open
speekha opened this issue Nov 20, 2024 · 10 comments
Open

Incorrect retries on connection that still succeeded #8587

speekha opened this issue Nov 20, 2024 · 10 comments
Labels
bug Bug in existing code

Comments

@speekha
Copy link

speekha commented Nov 20, 2024

We've wanted to upgrade OkHttp v4.x for quite a while now, but we can't because of some change regarding the connection pool and its impact on the retry policy. In some cases, we can see a connection going to a server and being answered (we use proxyman to track network flows, and we can see both request and response going through), but for some reason, OkHttp decides to silently drop that connection even though it was successful and retry it (not sure if the connection was deemed stale and thus closed). So we see a second request going through in proxyman (which ends up with an error from the server in some cases because it was already processed the first time, authentication for instance), and in our code, the only result that we receive is that second one (the server error).

We've encountered the problem with all v 4.x versions that we've tested so far, but never had the problem with v3.x (currently 3.14.9). The exact conditions are hard to reproduce, but if you disable the retryOnConnectionFailure, you end up with an IOException. This means that for some reason, the socket was closed by OkHttp v4.x, in a way that did not happen in OkHttp v3.x, leading to this exception:

Error response
java.io.IOException: unexpected end of stream on https://www.xxxxxxxxxx.fr/...
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:210)
at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:110)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:335)
at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:180)
at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:110)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:525)
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:210)
at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:110)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:180)

Every time that we've tried to upgrade and faced the issue, reverting to OkHttp 3 solved the problem.

PS : I opened that issue a few month ago, but it got closed erroneously (the bug that was fixed had nothing to do with the original problem.

@speekha speekha added the bug Bug in existing code label Nov 20, 2024
@speekha
Copy link
Author

speekha commented Nov 20, 2024

Here's some additional logs leading up to the exception.

2024-07-11 16:01:30.624 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:30] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:01:30.630 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:30] Q10000 run again after 0 µs: OkHttp ConnectionPool
2024-07-11 16:01:30.630 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:30] Q10000 finished run in 9 ms: OkHttp ConnectionPool
2024-07-11 16:01:30.630 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:30] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:01:30.630 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:30] Q10000 run again after 938 ms: OkHttp ConnectionPool
2024-07-11 16:01:30.630 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:30] Q10000 finished run in 212 µs: OkHttp ConnectionPool
2024-07-11 16:01:31.571 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:31] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:01:31.572 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:31] Q10000 run again after 0 µs: OkHttp ConnectionPool
2024-07-11 16:01:31.573 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:31] Q10000 finished run in 2 ms: OkHttp ConnectionPool
2024-07-11 16:01:31.573 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:31] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:01:31.573 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:31] Q10000 run again after 4 s : OkHttp ConnectionPool
2024-07-11 16:01:31.573 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:31] Q10000 finished run in 191 µs: OkHttp ConnectionPool
2024-07-11 16:01:35.109 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:35] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:01:35.110 11418-14990 System.err W OkHttp Extra [2024-07-11 16:01:35] Q10000 finished run in 2 ms: OkHttp ConnectionPool
2024-07-11 16:23:58.278 11418-15506 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.278 11418-15507 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 already scheduled : OkHttp ConnectionPool
2024-07-11 16:23:58.280 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:23:58.280 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:23:58.281 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 finished run in 430 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.440 11418-15511 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.440 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:23:58.440 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:23:58.440 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 finished run in 285 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.592 11418-15506 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.593 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:23:58.593 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:23:58.594 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 finished run in 841 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.716 11418-15511 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.716 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:23:58.716 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:23:58.717 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 finished run in 316 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.783 11418-15506 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:23:58.783 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:23:58.783 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:23:58.783 11418-15510 System.err W OkHttp Extra [2024-07-11 16:23:58] Q10000 finished run in 295 µs: OkHttp ConnectionPool
2024-07-11 16:28:58.602 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:28:58.624 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 run again after 0 µs: OkHttp ConnectionPool
2024-07-11 16:28:58.624 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 finished run in 30 ms: OkHttp ConnectionPool
2024-07-11 16:28:58.625 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:28:58.627 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 run again after 157 ms: OkHttp ConnectionPool
2024-07-11 16:28:58.628 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 finished run in 2 ms: OkHttp ConnectionPool
2024-07-11 16:28:58.785 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:28:58.787 11418-15510 System.err W OkHttp Extra [2024-07-11 16:28:58] Q10000 finished run in 2 ms: OkHttp ConnectionPool
2024-07-11 16:53:47.000 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:47] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:47.001 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:47] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:47.001 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:47] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:53:47.001 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:47] Q10000 finished run in 620 µs: OkHttp ConnectionPool
2024-07-11 16:53:47.253 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:47] Q10000 canceled : OkHttp ConnectionPool
2024-07-11 16:53:56.493 11418-15756 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:56.493 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 already scheduled : OkHttp ConnectionPool
2024-07-11 16:53:56.494 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:56.494 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:53:56.495 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 finished run in 539 µs: OkHttp ConnectionPool
2024-07-11 16:53:56.705 11418-15757 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:56.706 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:56.706 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:53:56.706 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 finished run in 1 ms: OkHttp ConnectionPool
2024-07-11 16:53:56.828 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:56.828 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:56.829 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:53:56.829 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:56] Q10000 finished run in 822 µs: OkHttp ConnectionPool
2024-07-11 16:53:57.050 11418-15757 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:57.050 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:57.050 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:53:57.050 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 finished run in 454 µs: OkHttp ConnectionPool
2024-07-11 16:53:57.123 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:57.123 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:57.123 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 run again after 300 s : OkHttp ConnectionPool
2024-07-11 16:53:57.123 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:57] Q10000 finished run in 226 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.423 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.423 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:58.423 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 run again after 298 s : OkHttp ConnectionPool
2024-07-11 16:53:58.424 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 finished run in 294 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.443 11418-15757 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.446 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:58.446 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 run again after 298 s : OkHttp ConnectionPool
2024-07-11 16:53:58.446 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 finished run in 3 ms: OkHttp ConnectionPool
2024-07-11 16:53:58.608 11418-15757 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.608 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:58.609 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 run again after 298 s : OkHttp ConnectionPool
2024-07-11 16:53:58.609 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 finished run in 317 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.642 11418-15757 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.642 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:58.643 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 run again after 298 s : OkHttp ConnectionPool
2024-07-11 16:53:58.643 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 finished run in 790 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.690 11418-15715 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.691 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:58.691 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 run again after 298 s : OkHttp ConnectionPool
2024-07-11 16:53:58.692 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 finished run in 1 ms: OkHttp ConnectionPool
2024-07-11 16:53:58.751 11418-15756 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-11 16:53:58.752 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 starting : OkHttp ConnectionPool
2024-07-11 16:53:58.753 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 run again after 298 s : OkHttp ConnectionPool
2024-07-11 16:53:58.753 11418-15721 System.err W OkHttp Extra [2024-07-11 16:53:58] Q10000 finished run in 1 ms: OkHttp ConnectionPool

@speekha
Copy link
Author

speekha commented Nov 20, 2024

Here's the events log:

2024-07-12 17:00:16.543 26646-27016 System.err W OkHttp Extra [2024-07-12 17:00:16] Q10000 scheduled after 0 µs: OkHttp ConnectionPool
2024-07-12 17:00:16.543 26646-26912 System.err W OkHttp Extra [2024-07-12 17:00:16] Q10000 starting : OkHttp ConnectionPool
2024-07-12 17:00:16.548 26646-26912 System.err W OkHttp Extra [2024-07-12 17:00:16] Q10000 run again after 294 s : OkHttp ConnectionPool
2024-07-12 17:00:16.549 26646-26912 System.err W OkHttp Extra [2024-07-12 17:00:16] Q10000 finished run in 5 ms: OkHttp ConnectionPool
2024-07-12 17:00:16.549 26646-27016 System.out I 0063 0.037 connectionAcquired
2024-07-12 17:00:16.549 26646-27016 System.out I 0063 0.037 requestHeadersStart
2024-07-12 17:00:16.549 26646-27016 System.out I 0063 0.037 requestHeadersEnd
2024-07-12 17:00:16.549 26646-27016 System.out I 0063 0.037 requestBodyStart
2024-07-12 17:00:16.549 26646-27016 System.out I 0063 0.037 requestBodyEnd
2024-07-12 17:00:18.022 26646-27016 System.out I 0063 1.510 responseHeadersStart
2024-07-12 17:00:18.023 26646-27016 System.out I 0063 1.511 responseHeadersEnd
2024-07-12 17:00:18.025 26646-27016 System.out I 0063 1.513 responseBodyStart
2024-07-12 17:00:18.026 26646-27016 System.out I 0063 1.514 responseBodyEnd
2024-07-12 17:00:18.026 26646-27016 System.out I 0063 1.514 connectionReleased
2024-07-12 17:00:18.026 26646-27016 System.out I 0063 1.515 callEnd
2024-07-12 17:00:18.032 26646-27016 System.out I 0063 1.520 canceled
2024-07-12 17:00:20.659 26646-27115 System.out I 0064 https://www….
2024-07-12 17:00:20.660 26646-27115 System.out I 0064 0.000 callStart
2024-07-12 17:00:20.665 26646-27016 System.out I 0064 0.005 connectionAcquired
2024-07-12 17:00:20.665 26646-27016 System.out I 0064 0.005 requestHeadersStart
2024-07-12 17:00:20.665 26646-27016 System.out I 0064 0.006 requestHeadersEnd
2024-07-12 17:00:20.666 26646-27016 System.out I 0064 0.006 requestBodyStart
2024-07-12 17:00:20.666 26646-27016 System.out I 0064 0.006 requestBodyEnd
2024-07-12 17:00:20.668 26646-27016 System.out I 0064 0.008 responseFailed
2024-07-12 17:00:20.670 26646-27016 System.out I 0064 0.011 connectionReleased
2024-07-12 17:00:20.670 26646-27016 System.out I 0064 0.011 callFailed
2024-07-12 17:05:10.697 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:10] Q10000 starting : OkHttp ConnectionPool
2024-07-12 17:05:10.713 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:10] Q10000 run again after 0 µs: OkHttp ConnectionPool
2024-07-12 17:05:10.714 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:10] Q10000 finished run in 57 ms: OkHttp ConnectionPool
2024-07-12 17:05:10.718 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:10] Q10000 starting : OkHttp ConnectionPool
2024-07-12 17:05:10.720 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:10] Q10000 run again after 2 s : OkHttp ConnectionPool
2024-07-12 17:05:10.721 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:10] Q10000 finished run in 3 ms: OkHttp ConnectionPool
2024-07-12 17:05:12.638 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:12] Q10000 starting : OkHttp ConnectionPool
2024-07-12 17:05:12.641 26646-26912 System.err W OkHttp Extra [2024-07-12 17:05:12] Q10000 finished run in 4 ms: OkHttp ConnectionPool

The log says response failed at 17:00:20.668, even though the request was received and the server answered.

@speekha
Copy link
Author

speekha commented Nov 20, 2024

Just confirmed that the failure has nothing to do with header sizes by checking an erroneous response:

  • the response that failed was 14218 bytes long
  • headers were 1434 bytes long
  • longest header was 403 bytes longs

@swankjesse
Copy link
Collaborator

swankjesse commented Nov 21, 2024

That’s surprising. There’s gonna be a bug in our code that enforces the 256 KiB limit on headers. The root cause exception is here:

Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:335)
at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:180)

The limit is supposed to start at (256 * 1024) and shrink as headers are processed.

Either way we should improve the error messaging here.

@swankjesse
Copy link
Collaborator

Do you have a URL that consistently triggers this? If you’d like to share it with me privately, my email address is posted at the bottom of publicobject.com.

@speekha
Copy link
Author

speekha commented Nov 21, 2024

@swankjesse No, I don't have a specific URL : it can happen on any URL we call. As far as I can tell, it's more of a time issue. The problem never happens during the first few minutes after launching the app, just after a few minutes. Thus my conclusion that it is probably more of a thread pool handling problem. As if a thread was reused, but when the response is received, the connection would be considered stale and discarded, even though it is clearly still working (the server received the request and answered it).

@swankjesse
Copy link
Collaborator

Interesting! I wonder if we could reproduce this with a single URL and a loop.

If you have any URL that I can use to attempt to reproduce this, that’ll help me to fix it.

@swankjesse
Copy link
Collaborator

(Or a test that uses MockWebServer and a loop!)

@speekha
Copy link
Author

speekha commented Nov 22, 2024

I don't have anything available, but I think you could use anything: as I mention, it can happen on pretty much any URL that we call.

I'll try and see if I can come up with a way to reproduce, but no guarantees.

@tom916
Copy link

tom916 commented Nov 25, 2024

In fact, the same problem can also occur in OkHttp 3.x. The fundamental reason is that there is something wrong with the judgment of "requestSendStarted = e!is ConnectionShutdownException".
For example, as shown in the following information: "okhttp3.internal.http2.StreamResetException caught in networkInterceptor".

okhttp3.internal.http2.StreamResetException is not ConnectionShutdownException

requestSendStarted = false

The HTTP request has already been sent out, but it is considered that the request sending has failed, and then the request is sent again.

It is very likely to happen on mobile devices. That is, just after a request is sent out, the network connection changes, such as switching from Wi-Fi to 4G.

error: okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL
at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:158)
at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:131)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.xxxxxx.core.http.RetrofitFactory.networkInterceptor$lambda$3(RetrofitFactory.kt:132)
at com.xxxxxx.core.http.RetrofitFactory.$r8$lambda$FEMrfWVAkhITHim8vIPzXv6mX0w(Unknown Source:0)
at com.xxxxxx.core.http.RetrofitFactory$$ExternalSyntheticLambda1.intercept(Unknown Source:18)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:127)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.xxxxxx.core.http.RetrofitFactory.$r8$lambda$n2cYmcgOuwqUUqzroLejnouixAc(Unknown Source:0)
at com.xxxxxx.core.http.RetrofitFactory$$ExternalSyntheticLambda2.intercept(Unknown Source:18)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.xxxxxx.core.http.RetrofitFactory.getInterceptor$lambda$9(RetrofitFactory.kt:425)
at com.xxxxxx.core.http.RetrofitFactory.$r8$lambda$ydCeRem1DXGu8KqBh-vj8zwTs-w(Unknown Source:0)
at com.xxxxxx.core.http.RetrofitFactory$$ExternalSyntheticLambda3.intercept(Unknown Source:18)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at me.jessyan.retrofiturlmanager.RetrofitUrlManager$1.intercept(RetrofitUrlManager.java:136)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:257)
at okhttp3.RealCall.execute(RealCall.java:93)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:46)
at io.reactivex.Observable.subscribe(Observable.java:12284)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
at io.reactivex.Observable.subscribe(Observable.java:12284)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:933)"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

3 participants