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

Potential failure on CallServerInterceptor if writeRequestHeader fails #8283

Open
gdrehmer opened this issue Mar 14, 2024 · 1 comment
Open
Labels
bug Bug in existing code
Milestone

Comments

@gdrehmer
Copy link

gdrehmer commented Mar 14, 2024

Unfortunately this bug is hard to replicate and to create a failing test.
But I hope it still gets attention.

We've noticed that there is a big number of crashes in our customer base after upgrading from OkHttp 4.9.3 to version 4.12.0, as per stacktrace below.

We've also noticed a change in 4.11 could be related to that:

Read the response even if writing the request fails (#6295) (#7453)

e46a200

It seems that a change has been introduced in CallServerInterceptor which moved the exchange.write* operations into a try/catch block (I suppose by design, to fix the issue as referenced in the commit).

However, the effect of that could be that the following block, the exchange.readResponseHeaders might be executed with state set to 0 (IDLE, not initalised), if the previous exchange.writeRequestHeaders(request) operation failed for any reason apart from ConnectionShutdownException. The readResponseHeaders has a guard statement which would throw an exception if state == 0.

I couldn't find a way which could cause the exchange.writeRequestHeaders call to raise an exception, but we are observing many cases (it is our top crash, affecting thousands of customers in a couple of days after rollout).

It is important to note that we also updated from Okio 3.0.0 to 3.7.0 in the same release.

Stacktrace:

Exception java.lang.IllegalStateException: state: 0
  at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders (Http1ExchangeCodec.kt)
  at okhttp3.internal.connection.Exchange.readResponseHeaders (Exchange.kt)
  at okhttp3.internal.http.CallServerInterceptor.intercept (CallServerInterceptor.kt)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.kt)
  at okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.kt)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.kt)
  at okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.kt)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.kt)
  at okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.kt)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.kt)
  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.kt)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.kt)
  at my.company.SomeInterceptor 
  (...)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.kt)
  at okhttp3.internal.connection.RealCall.getREsponseWithInterceptorChain$okhttp (RealCall.kt)
  at okhttp3.internal.connection.RealCall$AsyncCall.run (RealCall.kt)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:644)
  at java.lang.Thread.run (Thread.java:1012)

@gdrehmer gdrehmer added the bug Bug in existing code label Mar 14, 2024
@gdrehmer gdrehmer changed the title Potential failure Potential failure on CallServerInterceptor if writeRequestHeader fails Mar 14, 2024
@yschimke
Copy link
Collaborator

yschimke commented Mar 14, 2024

Probably a dupe of #6853

I'll take a look again on the weekend.

@swankjesse swankjesse added this to the 5.0 milestone Apr 4, 2024
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