Repository navigation
test/load_stats: Fix use-after-free in respondToHealthCheck - #48867
Merged
Merged
Conversation
FakeStream::encodeHeaders() posts a callback capturing the stream to the upstream connection thread and returns. respondToHealthCheck() is called back to back, and each call's waitForNewStream() replaces health_check_request_, deleting the previous FakeStream on the main thread while its posted callback may still be pending. TSAN caught this as a heap-use-after-free in EmptyLocalityAfterHealthCheckFailure. Wait for the connection's posted callbacks to drain before returning. Signed-off-by: Ryan Northey <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the callback-synchronization change intended to prevent a use-after-free.
No open issues 🎉
What changed in this PR
Fixes a use-after-free in the load-stats integration test helper by waiting for posted connection callbacks to finish before a subsequent health check replaces the stream.
Changes:
- Calls
waitForNoPost()after encoding the health-check response and asserts success. - Documents why the wait is needed to protect the stream’s lifetime.
| File | Description |
|---|---|
test/integration/load_stats_integration_test.cc |
Synchronizes health-check response callbacks before allowing stream replacement. |
Review effort: Balanced
phlax
enabled auto-merge (squash)
October 30, 2026 12:12
jwendell
approved these changes
Oct 30, 2026
This was referenced Nov 12, 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.
FakeStream::encodeHeaders() posts a callback capturing the stream to the upstream connection thread and returns. respondToHealthCheck() is called back to back, and each call's waitForNewStream() replaces health_check_request_, deleting the previous FakeStream on the main thread while its posted callback may still be pending. TSAN caught this as a heap-use-after-free in EmptyLocalityAfterHealthCheckFailure.
Wait for the connection's posted callbacks to drain before returning.