Repository navigation
test(okhttp): Wait until the reader is blocked before closing the body - #6604
Merged
Merged
Conversation
The concurrent close test signaled right after the reader got the first chunk, before it entered the next read(). When close() landed in that gap, the reader's next read() threw Okio's "closed" IllegalStateException, the thread died, and the test timed out waiting for it. ParkingSource now signals right before it blocks, so close() always lands while the reader is inside read(). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
📲 Install BuildsAndroid
|
romtsn
marked this pull request as ready for review
November 13, 2026 09:46
romtsn
requested review from
0xadam-brown and
markushi
and removed request for
a team
November 13, 2026 09:46
romtsn
enabled auto-merge (squash)
November 13, 2026 09:49
markushi
approved these changes
Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📜 Description
Fixes the flaky
CapturedResponseBodyTest > reports once when the body is closed while another thread is reading it.The test signaled "the reader is reading" right after the reader got the first chunk, before the reader entered the next
read(). Whenwrapper.close()landed in that gap, it closed the innerBufferedSourcefirst. The reader's nextread()then threw Okio'sIllegalStateException("closed"), the reader thread died, andreadDonenever counted down:ParkingSourcenow counts down aparkedlatch right before it blocks, and the test waits for that instead.close()then always lands while the reader is blocked insideread(), which is the situation the test is about. With a 300 ms sleep in the old gap the test failed every time before this change and passes with it.Test-only change, no SDK code touched.
💡 Motivation and Context
The test failed in 4 of the last 6 failed
Buildruns on unrelated branches this week.💚 How did you test it?
Reproduced locally with a widened gap, verified the fix under the same gap, then ran the class 3 times without it.
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
#skip-changelog
🤖 Generated with Claude Code