okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

not recover error of `REFUSED_STREAM error`

Open caojiajun opened this issue 1 year ago • 3 comments

okhttpclient version: 4.9.3

occasional occurrence this error, and will not recover on its own, util restart process

okhttp3.internal.http2.StreamResetException: stream was reset: REFUSED_STREAM
	at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.kt:148)
	at okhttp3.internal.http2.Http2ExchangeCodec.readResponseHeaders(Http2ExchangeCodec.kt:96)
	at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.ConnectInterceptor.intercept$sentryProxy(ConnectInterceptor.kt:34)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt)
	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.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

caojiajun avatar Sep 08 '24 00:09 caojiajun

There is logic to handle repeated refused stream failures and tests

https://github.com/square/okhttp/blob/master/okhttp%2Fsrc%2Fmain%2Fkotlin%2Fokhttp3%2Finternal%2Fconnection%2FRealConnection.kt

Without repro steps, I'm not sure how we can help you.

yschimke avatar Sep 08 '24 06:09 yschimke

It's occasional, so I could not provide repro steps.

Is there any known bug/issue which can not recover on its own? I will upgrade to latest version 4.12.0

caojiajun avatar Sep 08 '24 08:09 caojiajun

Not by known issues.

yschimke avatar Sep 08 '24 08:09 yschimke

Closing as can't reproduce, will reopen if it can be.

It's very possible an OkHttp bug, but could also be app or server bug.

yschimke avatar Nov 04 '24 21:11 yschimke

@caojiajun It seems I faced a similar issue and trying to investigate it. In your case, was it reproducible after the network disconnection/reconnection? Was there anything related to a Proxy or a VPN?

dvkolesnikov avatar Jan 17 '25 14:01 dvkolesnikov

@caojiajun If you are using Android, use a real device instead of an emulator, and you will see the stability.

I solved it by using a real device

hoangduchuu avatar Aug 13 '25 18:08 hoangduchuu