Skip to content

Integration test deflake attempt - #47096

Merged
ravenblackx merged 5 commits into
envoyproxy:mainfrom
ravenblackx:flake
Sep 3, 2026
Merged

ravenblackx merged 5 commits into
envoyproxy:mainfrom
ravenblackx:flake

Conversation

@ravenblackx

@ravenblackx ravenblackx commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting was test/extensions/filters/http/on_demand:on_demand_integration_test, which is flaky about 1/1000. An example failure can be seen here or here.

[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]

The theory of this fix is from a deep AI inspection using GPT Sol. I understand what the change is doing and have reviewed it, but I wouldn't bet heavily on it actually fixing the problem.

The explanation is, cleanupUpstreamAndDownstream() previously waited only for the fake upstream’s local socket close. This did not guarantee that Envoy’s worker had received the FIN and removed the connection from its HTTP connection pool. A subsequent request could therefore briefly reuse the closed connection instead of creating a new one, causing waitForNextUpstreamConnection() to time out as the request never provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and waits for Envoy to close the reverse direction, thereby proving Envoy observed the shutdown so it's really cleaned up. It then runs a worker-thread barrier that effectively drains the events in the dispatchers, to ensure Envoy’s connection-close callbacks have removed the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support half-close, so the same race-flake might still be available if any test uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is still included, which may suffice to make even those cases less flaky, given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Raven Black <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #47096 was opened by ravenblackx.

see: more, trace.

@ravenblackx
ravenblackx marked this pull request as ready for review August 31, 2026 21:55
phlax

This comment was marked as resolved.

@ravenblackx

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Raven Black <[email protected]>
@ravenblackx

This comment was marked as outdated.

@ravenblackx

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Raven Black <[email protected]>
@ravenblackx

Copy link
Copy Markdown
Contributor Author

/retest

@ravenblackx

ravenblackx commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor Author

/retest

#47167 attempts to deflake the unrelated flake that keeps failing here.
And #47176 makes it so retest in this form will work in future.

@ravenblackx

Copy link
Copy Markdown
Contributor Author

/retest

@ravenblackx

Copy link
Copy Markdown
Contributor Author

bot review ...

Accommodated.

@ravenblackx
ravenblackx merged commit 9a1cf7c into envoyproxy:main Sep 3, 2026
28 checks passed
@ravenblackx
ravenblackx deleted the flake branch September 3, 2026 19:34
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 16, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 17, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit that referenced this pull request Nov 17, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
Signed-off-by: Ryan Northey <[email protected]>
phlax pushed a commit to phlax/envoy that referenced this pull request Nov 18, 2026
Commit Message: Integration test deflake attempt
Additional Description: The specific integration test this is targeting
was `test/extensions/filters/http/on_demand:on_demand_integration_test`,
which is flaky about 1/1000. An example failure can be seen
[here](https://github.com/envoyproxy/envoy/actions/runs/33410166780/job/99547577287)
or
[here](https://mordenite.cluster.engflow.com/actions/executions/ChB2N1ZVMpJHK4_9l1Z-2xVzEgdkZWZhdWx0GiUKINCPT4uyt_PlqlFcPUOCGYYfgQpXTBSMrjzdX1EDoaPVEKADIAAoAQ==).
```
[ RUN      ] IpVersionsClientType/OnDemandVhdsIntegrationTest.MultipleUpdates/IPv4_EnvoyGrpc_Unified_Rds
[2026-08-31 15:58:17.696][59507][critical][assert] [test/integration/http_integration.cc:574] assert failure: 0. Details: Timed out waiting for new connection.
[2026-08-31 15:58:17.696][59507][error][envoy_bug] [./source/common/common/assert.h:60] stacktrace for envoy bug
[2026-08-31 15:58:17.735][59507][error][envoy_bug] [./source/common/common/assert.h:64] #0 Envoy::HttpIntegrationTest::waitForNextUpstreamConnection() [0x56186bb8a1a9]
[2026-08-31 15:58:17.756][59507][error][envoy_bug] [./source/common/common/assert.h:64] #1 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb88308]
[2026-08-31 15:58:17.782][59507][error][envoy_bug] [./source/common/common/assert.h:64] #2 Envoy::HttpIntegrationTest::waitForNextUpstreamRequest() [0x56186bb8ab31]
[2026-08-31 15:58:17.797][59507][error][envoy_bug] [./source/common/common/assert.h:64] #3 Envoy::(anonymous namespace)::OnDemandVhdsIntegrationTest_MultipleUpdates_Test::TestBody() [0x56186ba2b865]
[2026-08-31 15:58:17.814][59507][error][envoy_bug] [./source/common/common/assert.h:64] #4 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f366344]
[2026-08-31 15:58:17.829][59507][error][envoy_bug] [./source/common/common/assert.h:64] #5 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34af86]
[2026-08-31 15:58:17.849][59507][error][envoy_bug] [./source/common/common/assert.h:64] #6 testing::Test::Run() [0x56186f332347]
[2026-08-31 15:58:17.868][59507][error][envoy_bug] [./source/common/common/assert.h:64] #7 testing::TestInfo::Run() [0x56186f332c31]
[2026-08-31 15:58:17.884][59507][error][envoy_bug] [./source/common/common/assert.h:64] #8 testing::TestSuite::Run() [0x56186f3333ca]
[2026-08-31 15:58:17.900][59507][error][envoy_bug] [./source/common/common/assert.h:64] #9 testing::internal::UnitTestImpl::RunAllTests() [0x56186f340f53]
[2026-08-31 15:58:17.915][59507][error][envoy_bug] [./source/common/common/assert.h:64] #10 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x56186f368d34]
[2026-08-31 15:58:17.932][59507][error][envoy_bug] [./source/common/common/assert.h:64] #11 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x56186f34cfd6]
[2026-08-31 15:58:17.948][59507][error][envoy_bug] [./source/common/common/assert.h:64] #12 testing::UnitTest::Run() [0x56186f34085b]
[2026-08-31 15:58:17.965][59507][error][envoy_bug] [./source/common/common/assert.h:64] #13 RUN_ALL_TESTS() [0x56186df8b9a1]
[2026-08-31 15:58:17.982][59507][error][envoy_bug] [./source/common/common/assert.h:64] #14 Envoy::TestRunner::runTests() [0x56186df8af59]
[2026-08-31 15:58:17.998][59507][error][envoy_bug] [./source/common/common/assert.h:64] #15 main [0x56186df88e20]
```

The theory of this fix is from a deep AI inspection using GPT Sol. I
understand what the change is doing and have reviewed it, but I wouldn't
bet heavily on it actually fixing the problem.

The explanation is, `cleanupUpstreamAndDownstream()` previously waited
only for the fake upstream’s local socket close. This did not guarantee
that Envoy’s worker had received the FIN and removed the connection from
its HTTP connection pool. A subsequent request could therefore briefly
reuse the closed connection instead of creating a new one, causing
waitForNextUpstreamConnection() to time out as the request never
provokes a new connection.

For TCP upstreams, this cleanup now half-closes the fake upstream and
waits for Envoy to close the reverse direction, thereby proving Envoy
observed the shutdown so it's *really* cleaned up. It then runs a
worker-thread barrier that effectively drains the events in the
dispatchers, to ensure Envoy’s connection-close callbacks have removed
the old pool client, before cleanup returns.

HTTP/3 still retains the previous behavior because QUIC does not support
half-close, so the same race-flake might still be available if any test
uses HTTP/3 upstreams with a similar sequence of events.

For some cases where half-close isn't supported, the worker-barrier is
still included, which may suffice to make even those cases less flaky,
given that the flakiness this targets was already around a 1/1000 case.

Risk Level: Test-only.
Testing: Yes it is.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

---------

Signed-off-by: Raven Black <[email protected]>
Backport note: only this change's own additions; the `deferred_read_enable`
constructor argument and `FakeHttpConnection::initialize()` that `main` had
before it are not on this branch. `cleanupUpstreamAndDownstream()` is as
on `main` after it.

(cherry picked from commit 9a1cf7c)
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