okhttp: Fix race condition overwriting MAX_CONCURRENT_STREAMS #12548
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does
This PR fixes a race condition in
OkHttpClientTransportwhereMAX_CONCURRENT_STREAMSsent by the server could be incorrectly overwritten by the client's default initialization.The fix simply reorders the initialization to happen before starting the reader thread, ensuring that any updates from the server are preserved.
Note on Testing
I attempted to add a deterministic reproduction test, but reliably simulating this specific race condition proved difficult without intrusive changes.
I request reviewers to primarily verify the logical correctness of the reordering. I am open to collaborating with the team to develop a suitable test case if required.
Future Work
This PR covers Step 1 (Fixing the race condition) of the plan discussed in #11985.
I plan to follow up with Step 2 (Adding assertions to verify no pending streams exist) in a separate PR.
Part of #11985