Skip to content

test: Fix use-after-free flake in ratelimit integration test cleanup - #49172

Merged
phlax merged 1 commit into
envoyproxy:mainfrom
phlax:test-ratelimit-cleanup-wait-disconnect
Nov 11, 2026
Merged

phlax merged 1 commit into
envoyproxy:mainfrom
phlax:test-ratelimit-cleanup-wait-disconnect

Conversation

@phlax

@phlax phlax commented Nov 11, 2026

Copy link
Copy Markdown
Member

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.

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

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 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 jwendell closed this Nov 11, 2026
@jwendell jwendell reopened this Nov 11, 2026
@phlax
phlax merged commit 573c066 into envoyproxy:main Nov 11, 2026
32 checks passed
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]>
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