Skip to content

test(okhttp): Wait until the reader is blocked before closing the body - #6604

Merged
romtsn merged 1 commit into
mainfrom
fix/okhttp-captured-body-flaky-test
Nov 13, 2026
Merged

romtsn merged 1 commit into
mainfrom
fix/okhttp-captured-body-flaky-test

Conversation

@romtsn

@romtsn romtsn commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

📜 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(). When wrapper.close() landed in that gap, it closed the inner BufferedSource first. The reader's next read() then threw Okio's IllegalStateException("closed"), the reader thread died, and readDone never counted down:

Exception in thread "Thread-3" java.lang.IllegalStateException: closed
java.lang.AssertionError: the reader must finish once the body is closed

ParkingSource now counts down a parked latch right before it blocks, and the test waits for that instead. close() then always lands while the reader is blocked inside read(), 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 Build runs 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

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

#skip-changelog

🤖 Generated with Claude Code

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>
@sentry

sentry Bot commented Nov 13, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.64.0 (1) release

⚙️ sentry-android Build Distribution Settings

@romtsn romtsn added the ship-it PR is ready to merge from a reviewer perspective label Nov 13, 2026
@romtsn
romtsn marked this pull request as ready for review November 13, 2026 09:46
@romtsn
romtsn requested review from a team and adinauer as code owners November 13, 2026 09:46
@romtsn
romtsn requested review from 0xadam-brown and markushi and removed request for a team November 13, 2026 09:46
@romtsn
romtsn enabled auto-merge (squash) November 13, 2026 09:49
@romtsn
romtsn merged commit 2e298a3 into main Nov 13, 2026
49 checks passed
@romtsn
romtsn deleted the fix/okhttp-captured-body-flaky-test branch November 13, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ship-it PR is ready to merge from a reviewer perspective

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants