Skip to content

test/load_stats: Fix use-after-free in respondToHealthCheck - #48867

Merged
phlax merged 1 commit into
envoyproxy:mainfrom
phlax:test-load-stats
Oct 30, 2026
Merged

phlax merged 1 commit into
envoyproxy:mainfrom
phlax:test-load-stats

Conversation

@phlax

@phlax phlax commented Oct 30, 2026

Copy link
Copy Markdown
Member

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.

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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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
phlax enabled auto-merge (squash) October 30, 2026 12:12
@phlax
phlax merged commit 1f19fae into envoyproxy:main Oct 30, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants