You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The calltimeout setting sometimes does not take effect #8014
The calltimeout setting sometimes does not take effect. For example, a 10s calltimeout is set, but sometimes it does not close after 10s, and finally closes around 1000s.
Reacted by KevinSgun, flebotany, Guy Stone and Alessandro Ciccimarra
I've been working on a chaos test which introduces 100% packet loss and this is causing all threads to become stuck - I think this is the same issue?
The scenario spins up the service, throws normal traffic at it and then introduces 100% packet loss - so there will be HTTP2 connections established and ready to be re-used.
17 Nov 2025 02:07:15,652 [WARN] Thread 11 is detected as stuck as it has been blocked for 943918 ms.
StuckThreadDetector$StuckThreadException: Thread is in [BLOCKED] state because it's blocked by OkHttp external-api-endpoint.com[1777] writeSynReset.
at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.kt:240)
at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.kt:225)
at okhttp3.internal.http2.Http2ExchangeCodec.writeRequestHeaders(Http2ExchangeCodec.kt:76)
at okhttp3.internal.connection.Exchange.writeRequestHeaders(Exchange.kt:63)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:41)
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)
Looking at the implementation, the thread could be blocked in writer.headers() or writer.flush() while holding the writer.withLock mutex?
My understanding is the thread is stuck in kernel space and not interruptible by Java timeouts - my callTimeout can't interrupt this thread since it's blocked in native I/O.
We've updated to 5.3.2 on 25th November and the frequency of the call timeout not triggering has reduced a lot compared to 5.2.0, but it is still happening.
Activity
swankjesse commentedon Oct 6, 2023
Yikes; that’s severe. I wonder if this is related to full write buffers on the outbound TCP socket. I believe that can be a problem!
yschimke commentedon Jan 20, 2024
@swankjesse What's the theory or observable way to reproduce or fake? A delegating Socket that blocks writes?
swankjesse commentedon Apr 1, 2024
Yeah, a server that doesn’t read anything should do it.
swankjesse commentedon Apr 1, 2024
(That’ll only catch a broken write timeout. A broken call timeout should still work fine.)
yschimke commentedon Jul 26, 2025
closing as not reproducible, although possible relates to duplex requests
alex859 commentedon Aug 31, 2025
Hello, we are currently investigating a similar issue using OkHttp 4.12.0.
Call timeout set to 3s on the OkHttp instance:
It did not trigger for ~10 minutes. Eventually a
InterruptedIOException("timeout")was thrown.From the OpenTelemetry trace there is sign of a
okhttp3.internal.http2.ConnectionShutdownExceptionthrown with the following stack trace:The issue lasted 7 minutes only on 1 out of 3 instances of our app, then it started behaving as expected.
Did you guys had another chance to look into this?
What's your advice to make sure that the timeout is applied?
Thanks.
swankjesse commentedon Oct 31, 2025
Reopening to consider @alex859’s crash.
alex859 commentedon Nov 3, 2025
Thank you @swankjesse for looking into this.
Since the last message we've updated to OkHttp 5.1.0 and the issue is still happening.
We now have a workaround that uses a coroutine managed timeout slightly higher than the call timeout set in OkHttp:
This avoids having a thread stuck waiting for minutes.
The exception we can see in AWS X-Ray is now different:
okhttp3.internal.http2.StreamResetExceptionstream was reset: CANCELOur next guess will be to force the connection to be over HTTP/1.1.
Is there anything we could do to help with the investigation?
alex859 commentedon Nov 6, 2025
We've tried enforcing HTTP/1.1 and we still get the same behaviour, but with a different excepion in X-Ray:
java.net.SocketExceptionSocket closedWe've found that the issue happens more often after upgrading to OkHttp 5.2.0.
yschimke commentedon Nov 6, 2025
I'm assuming the type of exception is the server closing your connection, because it notices a stall. While OkHttp isn't.
If so, we are still with trying to work out why OkHttp isn't honouring the call timeout.
jozzas commentedon Nov 17, 2025
I've been working on a chaos test which introduces 100% packet loss and this is causing all threads to become stuck - I think this is the same issue?
The scenario spins up the service, throws normal traffic at it and then introduces 100% packet loss - so there will be HTTP2 connections established and ready to be re-used.
Looking at the implementation, the thread could be blocked in
writer.headers()orwriter.flush()while holding thewriter.withLockmutex?My understanding is the thread is stuck in kernel space and not interruptible by Java timeouts - my
callTimeoutcan't interrupt this thread since it's blocked in native I/O.yschimke commentedon Nov 21, 2025
Can you test with 5.3.2
Possibly #9191
alex859 commentedon Nov 21, 2025
We will update, thanks.
alex859 commentedon Dec 18, 2025
Hello @yschimke ,
We've updated to 5.3.2 on 25th November and the frequency of the call timeout not triggering has reduced a lot compared to 5.2.0, but it is still happening.