Skip to content

vhds: fixed bugs where the on demand callbacks may be hung forever - #48000

Merged
wbpcode merged 9 commits into
envoyproxy:mainfrom
wbpcode:dev-fix-vhds
Oct 8, 2026
Merged

wbpcode merged 9 commits into
envoyproxy:mainfrom
wbpcode:dev-fix-vhds

Conversation

@wbpcode

@wbpcode wbpcode commented Oct 5, 2026

Copy link
Copy Markdown
Member

Commit Message: vhds: fixed bugs where the on demand callbacks may be hung forever

Additional Description:

This fixes two bugs that could leave an on-demand VHDS virtual host request waiting forever, hanging the downstream request until its own timeout.

1: repeated requests for an already answered alias wait for a response that may never come.

When the server answers an on-demand alias — including answering with an empty resource, meaning the virtual host doesn't exist — a later request for the same domain sent a new delta subscribe for the alias and queued a callback waiting for the response. Per the xDS protocol, a server receiving a repeated resource_names_subscribe entry must re-send the resource even if the client appears subscribed and up to date. In practice the major control planes don't implement this: go-control-plane (and therefore everything built on it, e.g. Envoy Gateway) diffs against the client's acked versions and silently parks the watch, and Istio treats the request as an ACK (its one AlwaysRespond escape hatch only covers CDS→EDS/LDS→RDS warming). Against such servers the queued callback never resolves.

Fix: RouteConfigUpdateReceiver now tracks every resource id (virtual host name or alias) answered by the current VHDS subscription (vhdsResourceIdAnswered()). requestVirtualHostsUpdate() answers a request for an already answered id locally from the published route configuration, without another round trip. This is safe because the delta subscription to the alias is persistent: if the virtual host appears, changes, or is removed later, the server pushes an update on its own. The answered set is cleared whenever the VHDS subscription is replaced or dropped by an RDS update, since the new subscription carries no guarantee of pushes for previously answered ids.

2: callbacks queued against a superseded warming update are never resolved.

Callback resolution on publish only consulted resourceIdsInLastVhdsUpdate(). If a VHDS update carrying the requested alias was superseded by another update while still warming, the superseded update's resource ids were discarded, so a callback queued against them never resolved even though the eventually published configuration carried its answer.

Fix: on each publish, queued callbacks are also resolved against all accumulated answered ids, not just the ids of the update being published.

Both fixes apply to the dynamic (RDS) and static route configuration providers and are guarded by a runtime flag.

Risk Level: Low — the new behavior is limited to the on-demand VHDS path and guarded by a runtime flag.
Testing: unit.
Docs Changes: N/A
Release Notes: added.
Runtime guard: envoy.reloadable_features.vhds_answered_alias_cache (default true; set to false to restore the previous behavior)

@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: #48000 was opened by wbpcode.

see: more, trace.

Signed-off-by: wbpcode <[email protected]>
Signed-off-by: wbpcode <[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.

Copilot review overview

🟡 Changes recommended

Unconditional state resets prevent the runtime guard from fully restoring legacy callback behavior.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes on-demand VHDS callbacks that could remain unresolved by caching answered aliases and resolving callbacks from published configurations.

Changes:

  • Tracks requested and answered VHDS resource IDs.
  • Resolves repeated and superseded-update callbacks locally.
  • Adds runtime guarding, release notes, and unit coverage.
File Description
envoy/​router/​route_config_update_receiver.h Exposes answered-resource lookup.
source/​common/​router/​route_config_update_receiver_impl.h Stores requested and answered IDs.
source/​common/​router/​route_config_update_receiver_impl.cc Maintains answered-ID state.
source/​common/​router/​rds_impl.cc Resolves dynamic-provider callbacks locally.
source/​common/​router/​static_route_provider_impl.cc Resolves static-provider callbacks locally.
source/​common/​router/​BUILD Adds runtime dependencies.
source/​common/​runtime/​runtime_features.cc Registers the runtime guard.
test/​common/​router/​vhds_test.cc Tests answer-cache lifecycle.
test/​common/​router/​rds_impl_test.cc Tests dynamic-provider behavior.
test/​common/​router/​static_route_provider_impl_test.cc Tests static-provider behavior.
changelogs/​current/​bug_fixes/​vhds__on_demand_requests_waiting_forever.rst Documents the fix and rollback guard.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@xuanmin-zhu

Copy link
Copy Markdown
Contributor

nice, thanks for the quick fix!

Resolving queued callbacks against the previous subscription's last
update ids on the superseding publish is a pre-existing and rare
behavior, and resource_ids_in_last_update_ is slated for removal once
the vhds_answered_alias_cache runtime guard is removed. Keep the
previous behavior to keep this change small.

Signed-off-by: wbpcode <[email protected]>
@wbpcode

wbpcode commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

/retest

@wdauchy

wdauchy commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. One interaction with the on_demand filter after #47183: when VHDS delivers the requested virtual host but none of its routes match the request, onRouteConfigUpdateCompletion() re-runs decodeHeaders(), which requests the same virtual host again. Today the second request is deduplicated and the request waits until the stream idle timeout. With this PR it would be answered locally with host_exists=true, and the filter would request it again.

#48079 makes the filter continue to the router (404) when the refreshed route config still has no matching route, which avoids the repeated requests. Would you prefer to handle it here, or in #48079?

This is based on reading the code; I have not run #48000 together with the filter.

@wbpcode

wbpcode commented Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

cc @wdauchy seems it another independent bug of the on demand filter implementation. i will inclined to fix it in your independent PR. Could you also do a formal review to my PR and may be also the ODCDS one #48024 to see if there are any issues? Thanks!

@wdauchy wdauchy 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, the approach looks correct to me, including the guard-off path after 1f415b5. Since #46216, a repeat subscribe for an alias the watch already holds is dropped in WatchMap::appendWatchInterest(), so without this PR the second request waits until the stream timeout with any control plane. That would be worth saying in the description and changelog, and an integration test through the real delta mux would cover it (inline). The no-matching-route case is handled in #48079. Inline comments are non-blocking.

Comment thread test/common/router/rds_impl_test.cc Resolved
if (!maybe_still_alive.lock()) {
return;
}
const std::string alias = VhdsSubscription::domainNameToAlias(

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.

Moving domainNameToAlias(...) into the main-thread lambda also removes a worker-side read of the proto that the main thread replaces on publish. Maybe mention it in the description.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This isn't a user observable changes. I inclined to avoid the description be more complex.

Comment thread test/common/router/vhds_test.cc Resolved
Comment thread test/common/router/vhds_test.cc Resolved
Comment thread test/common/router/rds_impl_test.cc Resolved
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]>
@wbpcode

wbpcode commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

/retest

1 similar comment
@wbpcode

wbpcode commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

/retest

agrawroh
agrawroh previously approved these changes Oct 8, 2026

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

Looks good! I had some nits but honestly wouldn't push for them


// A repeated on-demand request for a domain the server has already answered is answered from the
// published route configuration without another VHDS round trip.
TEST_F(StaticRouteConfigProviderImplTest, OnDemandRequestForAnsweredAliasIsAnsweredLocally) {

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.

Nit: This kinda hand-rolls the setup that StaticVhdsOnDemandTest::setupWithVhds is doing a couple of lines below. Could we move it into the fixture?

rds_vhost->set_name("vhost_rds1");
rds_vhost->add_domains("vhost.rds.first");
EXPECT_OK(config_update_info->onRdsUpdate(updated_route_config, "2"));
EXPECT_TRUE(config_update_info->vhdsResourceIdAnswered("vhost1"));

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.

Nit: This only asserts whether the answered flag survives the RDS update but not that the published config still has vhost1.

Signed-off-by: wbpcode <[email protected]>
@agrawroh

agrawroh commented Oct 8, 2026

Copy link
Copy Markdown
Member

/retest

1 similar comment
@wbpcode

wbpcode commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

/retest

@wbpcode
wbpcode enabled auto-merge (squash) October 8, 2026 16:40
@wbpcode
wbpcode merged commit 106c34d into envoyproxy:main Oct 8, 2026
27 checks passed
@wbpcode
wbpcode deleted the dev-fix-vhds branch October 14, 2026 14:49
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.

5 participants