Skip to content

on_demand: disable recreateStream for successful on-demand VHDS - #47183

Merged
wbpcode merged 5 commits into
envoyproxy:mainfrom
wdauchy:fix/odcds-vhds-no-recreate-stream
Oct 5, 2026
Merged

wbpcode merged 5 commits into
envoyproxy:mainfrom
wdauchy:fix/odcds-vhds-no-recreate-stream

Conversation

@wdauchy

@wdauchy wdauchy commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message: disable recreateStream for successful on-demand VHDS.

Additional Description:
This mirrors the on-demand CDS fix in #43163 for the VHDS path. Before this
change, when OnDemandRouteUpdate::onRouteConfigUpdateCompletion resolved a
previously-missing virtual host, recreateStream(nullptr) was invoked, which
re-runs the entire filter chain, so non-idempotent filters sitting before
the on_demand filter run twice. With this change the VHDS callback
continues decoding the existing stream instead. A crash in recreateStream()
on this path was also observed in production and is avoided as well.

To make continueDecoding route to the freshly-discovered virtual host, a new
StreamFilterCallbacks method refreshRouteConfigSnapshot() re-snaps
snapped_route_config_ from the route config provider. Without this re-snap
the resumed router lookup resolves against the pre-VHDS snapshot taken at
request start and 404s. The ODCDS sibling does not need this because cluster
lookup goes through getThreadLocalCluster() per request rather than the
per-stream route snapshot.

The new path is gated by
envoy.reloadable_features.on_demand_vhds_no_recreate_stream (default true),
mirroring envoy.reloadable_features.on_demand_cluster_no_recreate_stream.
Set the guard to false to restore the legacy recreate behavior.

Risk Level: moderate, this is a guarded behavior change.
Testing: unit (on_demand_filter_test), integration (vhds_integration_test).
Docs Changes: n/a
Release Notes: added (changelogs/current/behavior_changes)
Platform Specific Features: n/a

@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: #47183 was opened by wdauchy.

see: more, trace.

@wdauchy
wdauchy force-pushed the fix/odcds-vhds-no-recreate-stream branch 3 times, most recently from 31315de to f268fdf Compare September 4, 2026 05:41
@wdauchy
wdauchy marked this pull request as ready for review September 4, 2026 10:08
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #47183 was ready_for_review by wdauchy.

see: more, trace.

Commit Message: disable recreateStream for successful on-demand VHDS.

Additional Description:
This mirrors the on-demand CDS fix in envoyproxy#43163 for the VHDS path. Before this
change, when OnDemandRouteUpdate::onRouteConfigUpdateCompletion resolved a
previously-missing virtual host, recreateStream(nullptr) was invoked, which
(a) re-runs the entire filter chain, double-triggering non-idempotent filters
sitting before the on_demand filter, and (b) reaches
ActiveStream::recreateStream -> Buffer::OwnedImpl::move on the buffered
request body. That buffer can be a sub-iteration zombie when the downstream
stream was reset while VHDS was in flight, producing a remote-reachable crash
(fault at 0x0 inside move), the same null-deref signature as the ODCDS crash
fixed by envoyproxy#43163. With this change the VHDS callback continues decoding the
existing stream instead.

To make continueDecoding route to the freshly-discovered virtual host, a new
StreamFilterCallbacks method refreshRouteConfigSnapshot() re-snaps
snapped_route_config_ from the route config provider. Without this re-snap the
resumed router lookup resolves against the pre-VHDS snapshot taken at request
start and 404s. The ODCDS sibling does not need this because cluster lookup
goes through getThreadLocalCluster() per request rather than the per-stream
route snapshot.

The new path is gated by
envoy.reloadable_features.on_demand_vhds_no_recreate_stream (default true),
mirroring envoy.reloadable_features.on_demand_cluster_no_recreate_stream. Set
the guard to false to restore the legacy recreate behavior.

Risk Level: moderate, this is a guarded behavior change.
Testing: unit (on_demand_filter_test), integration (vhds_integration_test).
Docs Changes: n/a
Release Notes: added (changelogs/current/behavior_changes)
Platform Specific Features: n/a

Signed-off-by: William Dauchy <[email protected]>
@wdauchy
wdauchy force-pushed the fix/odcds-vhds-no-recreate-stream branch from f268fdf to c2b90da Compare September 4, 2026 13:09

@adisuissa adisuissa 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.

Thanks, overall LGTM, but I'm not an expert here.
Left some high-level question and some minor comments.

return;
}

if (Runtime::runtimeFeatureEnabled(

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.

High-level question:
How will this impact a case where the OD-VHDS request is sent, but the response will timeout? (I believe that at the moment there's a bug in VHDS where the subscription doesn't time out, but that should probably be fixed)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is neutral for the timeout case. The guard only affects the route_exists == true branch: it replaces recreateStream() with refreshRouteConfigSnapshot() + clearRouteCache() + a re-drive of decodeHeaders(), otherwise continueDecoding(). It does not change when the callback fires.

If the update completes with the host unresolved, route_exists == false and both the old and new paths call continueDecoding(). If the subscription never times out and the callback never fires, the request parks; that is true before and after this PR, since we do not touch the subscription lifecycle. So it is a pre-existing, separate issue. I agree the VHDS subscription timeout should be fixed on its own.


// tests onRouteConfigUpdateCompletion() when redirect contains a body with trailers (fully read)
TEST_F(OnDemandFilterTest, OnRouteConfigUpdateCompletionRestartsActiveStreamWithTrailers) {
TestScopedRuntime scoped_runtime;

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.

Are all these tests with disabled runtime-flag should be removed after the runtime flag is removed?
Seems a bit strange that the impact of changing a behavior is removal of many tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are not removed by this PR. They are pinned to guard-off so the existing recreateStream() expectations still hold while the new behavior is the default. The new behavior has its own permanent test, OnRouteConfigUpdateCompletionNoRecreateStream. When the guard is removed later, only the tests for the deleted legacy branch go away; guard-on coverage stays. Same pattern as #43163. I can collapse the guard-off cases to one representative test if you prefer.

// the HCM filter chain. ``prependFilter`` inserts at the front of the list,
// so calling it with ``add-header-filter`` *after* ``on_demand`` leaves the
// final chain as: add-header-filter -> on_demand -> router.
class OnDemandVhdsRecreateStreamRegressionTest : public VhdsIntegrationTest {

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.

Why is a new test suite needed in this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The assertion needs a filter chain the base suite does not set up. It prepends on_demand then add-header-filter (chain: add-header-filter -> on_demand -> router) and counts how often x-header-to-add is stamped upstream: once means continueDecoding() (guard on), twice means recreateStream() (guard off). The base suite installs neither filter. The subclass keeps that setup isolated, matching #43163. I can inline it into VhdsIntegrationTest instead if you prefer.

@wdauchy

wdauchy commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Replies inline. In short: the guard only changes the successful-resolution branch of onRouteConfigUpdateCompletion(), the disabled-flag tests are transitional coverage for the legacy path (as in #43163), and the new fixture is needed for a specific filter chain. Happy to adjust.

@wdauchy

wdauchy commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

ping @adisuissa

Comment on lines +359 to +369
// ---------------------------------------------------------------------------
// Regression tests for the VHDS on-demand recreate-stream crash.
//
// OnDemandRouteUpdate::onRouteConfigUpdateCompletion (in
// source/extensions/filters/http/on_demand/on_demand_update.cc) historically
// called callbacks_->recreateStream(nullptr) when VHDS successfully resolved
// the host and the request body had been fully read. That recreate path ran
// ActiveStream::recreateStream at source/common/http/conn_manager_impl.cc
// which unconditionally dereferences filter_manager_.bufferedRequestData()
// via Buffer::OwnedImpl::move -- the same null-dereference signature as the ODCDS
// crash fixed by #43163 for the cluster-discovery path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems we will check this null case?

  const bool proxy_body = buffered_request_data != nullptr && buffered_request_data->length() > 0;
  if (proxy_body) {
    request_data->move(*buffered_request_data);
  }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did a quick glance the tests self. Seems fine to me. Could you simplify these comments to only explain what cases are tested?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, recreateStream() null-checks bufferedRequestData() before move(), so that comment was wrong. Removed it in e1e7f74, and dropped the same claim from the source comment, changelog and PR description in c129754.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in e1e7f74: each helper and test comment now only states the case it covers, and the class comment explains the add-header-filter counting once. Also dropped an unused buffer_impl.h include and its BUILD dep.

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM to the code. Seems reasonable to me. It's unnecessary to recreate the stream in this case.

Only comments to the tests. Thanks again. And please merge main because this PR is pending for a while.

/wait

Comment on lines +359 to +369
// ---------------------------------------------------------------------------
// Regression tests for the VHDS on-demand recreate-stream crash.
//
// OnDemandRouteUpdate::onRouteConfigUpdateCompletion (in
// source/extensions/filters/http/on_demand/on_demand_update.cc) historically
// called callbacks_->recreateStream(nullptr) when VHDS successfully resolved
// the host and the request body had been fully read. That recreate path ran
// ActiveStream::recreateStream at source/common/http/conn_manager_impl.cc
// which unconditionally dereferences filter_manager_.bufferedRequestData()
// via Buffer::OwnedImpl::move -- the same null-dereference signature as the ODCDS
// crash fixed by #43163 for the cluster-discovery path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did a quick glance the tests self. Seems fine to me. Could you simplify these comments to only explain what cases are tested?

Reduce the comments in OnDemandVhdsRecreateStreamRegressionTest to a
description of the case each test covers. Drop the inaccurate note that
recreateStream() unconditionally dereferences the buffered request data,
and remove the unused buffer_impl.h include and buffer_lib dependency.

Signed-off-by: William Dauchy <[email protected]>
Describe the change as avoiding a second run of the decoder filters
before on_demand, and drop the claim about how moving the buffered
request body could crash. Shorten the related source comment.

Signed-off-by: William Dauchy <[email protected]>
@wdauchy

wdauchy commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks. Merged main and simplified the test comments. I also reworded the rationale and in the PR description so it no longer claims a specific crash mechanism; the main point is that recreating the stream re-runs the filters before on_demand. on_demand_filter_test, vhds_integration_test and odcds_integration_test pass locally.

@wdauchy
wdauchy requested a review from wbpcode September 30, 2026 19:45
@wdauchy

wdauchy commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@wbpcode
wbpcode enabled auto-merge (squash) October 5, 2026 01:32
@wdauchy

wdauchy commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

/retest transients

@wbpcode
wbpcode merged commit d450cd2 into envoyproxy:main Oct 5, 2026
27 checks passed
@wdauchy
wdauchy deleted the fix/odcds-vhds-no-recreate-stream branch October 5, 2026 16:43
wbpcode pushed a commit that referenced this pull request Oct 8, 2026
… route (#48079)

Commit Message: on_demand: continue to the router when the on-demand
VHDS virtual host has no matching route.

Additional Description:
After #47183, onRouteConfigUpdateCompletion() re-runs decodeHeaders()
once VHDS reports that the
virtual host exists. route_exists only means the virtual host exists,
not that one of its routes
matches the request. If none match, decodeHeaders() requests the same
virtual host again. Since
#46216 that repeated request is not sent, so the request waits until the
stream idle timeout.
Before #46216 it was sent and answered again, so the request looped on
VHDS. The legacy
recreateStream() path has the same problem.

This change re-checks route() after refreshing the route config
snapshot. route_exists now means
a route was found, as the scoped RDS callback already reports. If no
route matches, the filter
continues to the router, which replies with a 404.

Tradeoff: a virtual host that only gains the matching route in a later
VHDS update is no longer
picked up while the request waits. Upstream never answered this case
before: the request looped
or waited until the stream idle timeout.

Related PRs:
- #48000 answers repeated VHDS requests locally. With that change, the
decodeHeaders() re-run
would get an immediate answer for the same virtual host and request it
again. Continuing to the
  router when no route matches avoids that.
- #44401 lets a VHDS virtual host replace an RDS virtual host with the
same name. If the VHDS copy
also has no route for the request, the request currently waits until the
stream idle timeout.
  With this change it gets a 404.

Risk Level: Low. Guarded, limited to on-demand VHDS.
Testing: New unit tests in on_demand_filter_test cover both values of
the new guard and of
on_demand_vhds_no_recreate_stream. New integration tests in
vhds_integration_test cover both
on_demand_vhds_no_recreate_stream values. Without the fix, the new tests
with the guard enabled
fail and the integration requests time out waiting for a response.
on_demand_filter_test,
vhds_integration_test, odcds_integration_test and
on_demand_integration_test pass.
Docs Changes: N/A
Release Notes: Added under changelogs/current/bug_fixes.
Platform Specific Features: N/A
Runtime guard:
envoy.reloadable_features.on_demand_vhds_require_route_match (default
true). Set
it to false to restore the previous behavior.

AI assistance: Cursor helped trace the issue and write the tests. I
reviewed and understand all
changes.

Signed-off-by: William Dauchy <[email protected]>
tomjzzhang pushed a commit to envoyproxy/nighthawk that referenced this pull request Oct 14, 2026
- Update ENVOY_COMMIT in MODULE.bazel to the latest Envoy commit, update bazel_dep versions to envoyproxy/envoy#48143, envoyproxy/envoy#48104, and refresh MODULE.bazel.lock
- Update tools/code_format/config.yaml to envoyproxy/envoy#47183
- Update .github/config.yml to envoyproxy/envoy#48145, envoyproxy/envoy#48134, envoyproxy/envoy#47758
- Update .bazelversion to envoyproxy/envoy#48114
- Update .bazelrc to envoyproxy/envoy#48140, envoyproxy/envoy#48101, envoyproxy/envoy#47957
- Update tools/base/requirements.txt

Signed-off-by: Jason Ye <[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