Repository navigation
test: Fix use-after-free flake in ratelimit integration test cleanup - #49172
Merged
phlax merged 1 commit intoNov 11, 2026
Merged
Conversation
`cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the cleanup change intended to prevent a codec lifetime race in rate-limit integration tests.
No open issues 🎉
What changed in this PR
This PR addresses a use-after-free flake in rate-limit integration test cleanup by waiting for the fake rate-limit connection to disconnect before its codec is destroyed.
Changes:
- Waits for disconnect after closing the connection and asserts that the wait succeeds.
- Documents why cleanup must wait for write-buffer draining to finish.
| File | Description |
|---|---|
test/extensions/filters/http/ratelimit/ratelimit_integration_test.cc |
Synchronizes connection shutdown before fixture teardown to prevent a codec lifetime race. |
Review effort: Balanced
jwendell
approved these changes
Nov 11, 2026
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 12, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]>
jwendell
pushed a commit
that referenced
this pull request
Nov 12, 2026
…49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 16, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 17, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
that referenced
this pull request
Nov 17, 2026
…49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/envoy
that referenced
this pull request
Nov 18, 2026
…nvoyproxy#49172) `cleanup()` closed the fake ratelimit connection with `FlushWrite` and returned without waiting for the disconnect. The fixture then destroyed the `FakeHttpConnection` codec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec's `ProtocolConstraints`. ASAN caught this as a heap-use-after-free in `ProtocolConstraints::releaseOutboundFrame()` in `ResponseHeaderHitsAddendOnStreamDone`, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs). Wait for the disconnect before returning. Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 573c066) Signed-off-by: Ryan Northey <[email protected]>
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.
cleanup()closed the fake ratelimit connection withFlushWriteand returned without waiting for the disconnect. The fixture then destroyed theFakeHttpConnectioncodec on the main thread while the fake upstream thread could still be draining the write buffer, whose drain trackers call into the codec'sProtocolConstraints.ASAN caught this as a heap-use-after-free in
ProtocolConstraints::releaseOutboundFrame()inResponseHeaderHitsAddendOnStreamDone, which sends the ratelimit response immediately before cleanup (5 failures in 1000 runs).Wait for the disconnect before returning.