Skip to content

config: fix a bug where the on demand subscription not works - #46216

Merged
htuch merged 8 commits into
envoyproxy:mainfrom
wbpcode:dev-fix-xds-on-demand-update
Oct 6, 2026
Merged

htuch merged 8 commits into
envoyproxy:mainfrom
wbpcode:dev-fix-xds-on-demand-update

Conversation

@wbpcode

@wbpcode wbpcode commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Commit Message: config: fix a bug where the on demand subscription not works
Additional Description:

In the previous xds implementation, the requestOnDemandUpdate() will update the resources in the discovery request but doesn't update the watch self which make the responded resource will be silently dropped.

The VHDS works because it use a namespace matching to match all resource with same prefix. The use_namespace_matching self is subscription level option, but will be affected all subscriptions under the same type_url. So, it more like a hack.
The ODCDS is a problem. The integration show it can never works correctly. 😞

Anyway, this PR fixed these problems by:

  • Added append to update subscription state and also the watch map.
  • Used a new subscription level accept() method to replace the use_namespace_matching which is more clearly.

Could close #46561

Risk Level: mid, core code change.
Testing: unit, integration.
Docs Changes: n/a.
Release Notes: added.
Platform Specific Features: n/a.

Comment on lines -329 to +337
if (options.use_namespace_matching_) {
// This is to prevent sending out of requests that contain prefixes instead of resource names
sub->second->sub_state_.updateSubscriptionInterest({}, {});
} else {
sub->second->sub_state_.updateSubscriptionInterest(added_removed.added_,
added_removed.removed_);
}
sub->second->sub_state_.updateSubscriptionInterest(added_removed.added_, added_removed.removed_);

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.

The use_namespace_matching_ here make it's impossible to subscribe other resource in the start() and update interest method because they all will be cleaned.

Now, we will always respect the resources set provided by the start() and updateResourceInterest() here, and use the accept() to customize the resource routing.

@wbpcode

wbpcode commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Also related to #44129

@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 for raising the bug, and proposing a fix.
To the best of my understanding, w.r.t. 'append', the proposed design essentially introduces the on-demand concept into the GrpcMuxWatch, which may weaken the abstraction and encapsulation of the on-demand concept. I believe the proposed design leaks that concept into the GrpcMux (similar to how the namespace-matching is a leak of the watched resources, which as you are pointing out is a problem). Note that Envoy already supports multiple GrpcSubscription object over the same GrpcMux (so the watch is updated correctly while there are dynamic "additions" to the watched objects).
Assuming that on-demand is for a named resource, I believe the issue can also be solved by introducing multiple GrpcSubscription objects (for each VDHS resource that needs to be fetched), that will be fetched over the same GrpcMux.

W.r.t. 'accept' I agree that there is an issue with VHDS. I think the issue is even a bit more challenging, for example, say there are 2 routes '/shared/prefix/route_1', and '/shared/prefix', which subscriptions would a VHDS for the two different routes will be invoked once a response comes back. In general, this is a challenge with wildcard subscriptions and it would be good to get a good solution for this. I'm not sure if the proposed aliasing solution is the right thing to do, but it seems to be a bit more explicit - telling the xDS system, what to 'accept' by defining it in the resource the client subscribes to.

[this]() {
subscription_->start(
{config_update_info_->protobufConfigurationCast().name()});
// Start with no concrete subscription; virtual hosts are fetched on demand.

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.

Is this a breaking change with the VHDS default wildcard subscription?

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.

Nope, this PR didn't change any behavior. The VHDS worked in a special way before.

It will specific a route configuration name (for example rc) in the start() But this rc will not be sent out because the use_namespace_matching won't add anything to the subscription state. See the #46216 (comment)

Then this rc will be used to match received resources based on prefix matching.

For control plane's perspective, nothing is changed.

@sschepens

Copy link
Copy Markdown
Contributor

Assuming that on-demand is for a named resource, I believe the issue can also be solved by introducing multiple GrpcSubscription objects (for each VDHS resource that needs to be fetched), that will be fetched over the same GrpcMux.

Wouldn't this be much more expensive than just adding resources to the watch? we could be talking of many thousands of resources.

@adisuissa

Copy link
Copy Markdown
Contributor

Wouldn't this be much more expensive than just adding resources to the watch? we could be talking of many thousands of resources.

Really depends on whether there's support for subscription removal or not.
Once a subscription is removed, for example when a listener is removed, then the proposed approach needs to keep track of whether there are multiple listeners on the same subscribed VHDS resource or not. The per-GrpcSubscription shifts that responsibility to the mechanism that is already implemented.

@wbpcode

wbpcode commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

To the best of my understanding, w.r.t. 'append', the proposed design essentially introduces the on-demand concept into the GrpcMuxWatch, which may weaken the abstraction and encapsulation of the on-demand concept. I believe the proposed design leaks that concept into the GrpcMux (similar to how the namespace-matching is a leak of the watched resources, which as you are pointing out is a problem). Note that Envoy already supports multiple GrpcSubscription object over the same GrpcMux (so the watch is updated correctly while there are dynamic "additions" to the watched objects).

I don't think this is actual problem. Note, we have supported update here. And the append is only a special update. And I actually want to support the on-demand update more generally, like to CDS self (not the ODCDS). Based on the delta xDS, the on-demand should be simple, cheap, light, and easy.

Assuming that on-demand is for a named resource, I believe the issue can also be solved by introducing multiple GrpcSubscription objects (for each VDHS resource that needs to be fetched), that will be fetched over the same GrpcMux.

Every GrpcSubscription for single resource (like a domain) is much more heavy if there are thousands resources. And if there are multiple resources/subscriptions, we still need to abstract a layer to manager all these subscriptions, like the XdstpOdcdsSubscriptionsManager. And a new subscriptions manager layer is more like a reproduce of current watch and watch map design.

I don't think multiple subscription is a bad idea. But with our current subscription and watch map's design, after this fix, a single subscription could manage a set of resource very well, and more efficient, easier to use. I guess there is no strong reason to use multiple subscriptions' solution.

Really depends on whether there's support for subscription removal or not.
Once a subscription is removed, for example when a listener is removed, then the proposed approach needs to keep track of whether there are multiple listeners on the same subscribed VHDS resource or not. The per-GrpcSubscription shifts that responsibility to the mechanism that is already implemented.

Our current underlying subscription and watch map design have supported the resource removal well. To expose a remove() is also very simple, because remove() is also another update only.
Although, until now, we didn't see the requirements to the removal.


In short conclusion, our current subscription and watch map are well designed for multiple resources in same subscription. And it match the actual requirement (one observer, multiple resources) very well. Fix it and enhance it should bring us more benefit rather than to deprecate it.

@wbpcode

wbpcode commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

W.r.t. 'accept' I agree that there is an issue with VHDS. I think the issue is even a bit more challenging, for example, say there are 2 routes '/shared/prefix/route_1', and '/shared/prefix', which subscriptions would a VHDS for the two different routes will be invoked once a response comes back. In general, this is a challenge with wildcard subscriptions and it would be good to get a good solution for this. I'm not sure if the proposed aliasing solution is the right thing to do, but it seems to be a bit more explicit - telling the xDS system, what to 'accept' by defining it in the resource the client subscribes to.

In very long time, we still need to handle canonical xDS. So, I guess the accept() still make sense in very long time. And there are two points:

  • Envoy is not actually interact with xDS protocols, it interact with specific xDS implementations, and in practice, they may be different. For example, in current implementations, the VHDS will send empty resource names which should be treat as subscribe all. But in implementation, the server treat it as on demand.
  • When supporting the on demand cds in Istio, the maintainers raised a requirement to allow Istio send additional clusters that Envoy not required directly (for tracing, logging and so on because these clusters will processed by on demand filter), with accept(), we can set a * and transfer the control to control plane.

Basically, accept() is used to provide more flexibility, and harmless if you don't use it.

@adisuissa

Copy link
Copy Markdown
Contributor

To the best of my understanding, w.r.t. 'append', the proposed design essentially introduces the on-demand concept into the GrpcMuxWatch, which may weaken the abstraction and encapsulation of the on-demand concept. I believe the proposed design leaks that concept into the GrpcMux (similar to how the namespace-matching is a leak of the watched resources, which as you are pointing out is a problem). Note that Envoy already supports multiple GrpcSubscription object over the same GrpcMux (so the watch is updated correctly while there are dynamic "additions" to the watched objects).

I don't think this is actual problem. Note, we have supported update here. And the append is only a special update. And I actually want to support the on-demand update more generally, like to CDS self (not the ODCDS). Based on the delta xDS, the on-demand should be simple, cheap, light, and easy.

How does it handle a removal of a subscription from the watcher?
What happens if there are 2 GrpcSubscription objects that have been added in different time subscribing to the same resource, and then one is deleted. Does the underlying GrpcMuxWatch keeps track of which GrpcSusbcription were needed for it?
I think this is the "abstraction" breaking that hopefully can be avoided by designing it a bit better.

Assuming that on-demand is for a named resource, I believe the issue can also be solved by introducing multiple GrpcSubscription objects (for each VDHS resource that needs to be fetched), that will be fetched over the same GrpcMux.

Every GrpcSubscription for single resource (like a domain) is much more heavy if there are thousands resources. And if there are multiple resources/subscriptions, we still need to abstract a layer to manager all these subscriptions, like the XdstpOdcdsSubscriptionsManager. And a new subscriptions manager layer is more like a reproduce of current watch and watch map design.

I don't think multiple subscription is a bad idea. But with our current subscription and watch map's design, after this fix, a single subscription could manage a set of resource very well, and more efficient, easier to use. I guess there is no strong reason to use multiple subscriptions' solution.

Really depends on whether there's support for subscription removal or not.
Once a subscription is removed, for example when a listener is removed, then the proposed approach needs to keep track of whether there are multiple listeners on the same subscribed VHDS resource or not. The per-GrpcSubscription shifts that responsibility to the mechanism that is already implemented.

Our current underlying subscription and watch map design have supported the resource removal well. To expose a remove() is also very simple, because remove() is also another update only. Although, until now, we didn't see the requirements to the removal.

Why isn't there a requirement for removal? What happens if the listener that subscribed to the VHDS resource is removed?
What if there are 2 listeners pointing to the same VHDS resource.
Why should the discussion be around VHDS? This is not a VHDS-specific change, but a generic xDS-level change, so it should be supported for other xDS-types as well, no?

In short conclusion, our current subscription and watch map are well designed for multiple resources in same subscription. And it match the actual requirement (one observer, multiple resources) very well. Fix it and enhance it should bring us more benefit rather than to deprecate it.

The breaking of that abstraction is one of the things that caused issues with on-demand out-of-sync subscriptions.
Note that watchers were added for GrpcMux, and not for filesystem/REST transport types. This was an intentional design choice to avoid having features that only work for one type and not for another.

@wbpcode

wbpcode commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

How does it handle a removal of a subscription from the watcher?
What happens if there are 2 GrpcSubscription objects that have been added in different time subscribing to the same resource, and then one is deleted. Does the underlying GrpcMuxWatch keeps track of which GrpcSusbcription were needed for it?
I think this is the "abstraction" breaking that hopefully can be avoided by designing it a bit better.

When a subscription is removed, it will be removed from the watch map. For specific resource, if the removed subscription is only one to subscribe the resource, the resource will be removed. If there are other subscriptions want this resource, resource will be kept.

Yeah, watch map have tracked everything. Every subscription's resource list and every resource is subscribed by which subscriptions.
And even you use single subscription for single resource, it will finally enter this watch map and be tracked by this same way.

@wbpcode

wbpcode commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

Why isn't there a requirement for removal? What happens if the listener that subscribed to the VHDS resource is removed?
What if there are 2 listeners pointing to the same VHDS resource.
Why should the discussion be around VHDS? This is not a VHDS-specific change, but a generic xDS-level change, so it should be supported for other xDS-types as well, no?

Sorry, I meant to remove a specific resource from a subscription. Until now, no related requirements. All your referred are cases to remove whole subscription. For these cases, they will be removed correctly as I described in the #46216 (comment)

And you are right, I only use VHDS as an example. This is general problem, and this PR is also a general fix for all xDS-types (i mean CDS/LDS/... and so on, not means file/rest/...).
After this PR, all xDS type could support on demand update easily.

@wbpcode

wbpcode commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

The breaking of that abstraction is one of the things that caused issues with on-demand out-of-sync subscriptions.
Note that watchers were added for GrpcMux, and not for filesystem/REST transport types. This was an intentional design choice to avoid having features that only work for one type and not for another.

Sorry. I didn't get you here. Could you explain a little more about the breaking of that abstraction? I personally think this is only a implementation bug because the existing abstraction (before this PR) have provided update() (in GrpcMuxWatch) and updateResourceInterest() (in Subscription), the new append() won't make thing worse because the append is only variant of update?
Or did you mean the exiting abstraction (before this PR) not in a correct direction? (I actually think the whole existing design is flexible and powerful, although can be better in some detail).

@wbpcode

wbpcode commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

BTW, to avoid there is any information gap, when I say observer, I mean a configuration receiver who implemented the SubscriptionCallbacks (onConfigUpdate/...), .

@wbpcode

wbpcode commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

After a rethinking and discuss with AI, did you mean the current design shouldn't leak the gRPC implementation detail like requestOnDemandUpdate/updateResourceInterest to Subscription abstraction because they are implementation dependent?

If you meant that, I guess it's too late to discuss that. GRPC is special from start. For example, the file xds even cannot support a the start() correctly because it has no name based discovery. Back to 10 years ago, we may could have better design. But for now, the canonical xDS is mature and almost no one complain the limit of file/rest, I guess it's fine to go head along current way and fix/improve the implementation/detail.

The next generation should is the xdstp, but it's another topic.

@wbpcode

wbpcode commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

/coverage

@repokitteh-read-only

Copy link
Copy Markdown

Coverage for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-cncf-pr/46216/coverage/index.html

For comparison, current coverage on main branch is here:

https://storage.googleapis.com/envoy-cncf-postsubmit/main/coverage/index.html

The coverage results are (re-)rendered each time the CI Envoy/Checks (coverage) job completes.

🐱

Caused by: a #46216 (comment) was created by @wbpcode.

see: more, trace.

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

Copy link
Copy Markdown
Contributor

@wbpcode and @adisuissa what should we do next here? Is there agreement on the approach?

@adisuissa

Copy link
Copy Markdown
Contributor

Sorry, been busy with other stuff.

I believe I've got an explicit example that shows something that is lacking with having multiple subscribed resources, that are not for a wildcard/collection subscription, multiplexed in the same GrpcSubscription.

Consider what happens in the Envoy side when a subscribed resource isn't found/missing on the server.
In this case the server can either not send a response for that resource, or if delta-xDS is used, send a response noting that the resource was removed. In Envoy this translates to notifying that the resource update has failed, and allows continue the warming of the rest of the dependent resources. Note that this happens on the GrpcSubscription object level (so the entire GrpcSubscription fails).

If one has multiple singleton (named) subscriptions over the same GrpcSubcription, there is no way to mark one of them as missing. In the case of VHDS, for example, I believe that currently there is a bug where waiting for an on-demand VHDS resource is without any limit, although there should be a timeout for waiting for that resource.

Now one can add all the features that are supported for GrpcSubscription into the "updateOnDemand()" method and try to create multiple timers inside, but IMHO it is probably not the right way to go.

@wbpcode

wbpcode commented Jul 25, 2026 •

Copy link
Copy Markdown
Member Author

Hello, @adisuissa , I agree all you said. It's not the perfect design and have obvious limit. But the design is not introduced by this PR. This PR's target also is not to provides a better design. The target here is only try to fix an existing bug of current implementation to make it works a little better.

Because this design (canonical xds and updateOnDemand()) is here for a while, and works for a long time. It's not perfect and may in flawed direction, I agree. But I think we still could to fix it.

We still could to construct our new on demand solution based on xdstp by create subscription for every new resource (like the new ondemand cds). But at same, to continuously evolve the canonical xDS is harmless anyway if it could meet our users's requirements.

This PR is only a fix and will make the canonical xDS easier to support delta/ondemand (sure, under you refferred limit). It won't block the developement of better design with xdstp and it's another scope's discussion.

@adisuissa

Copy link
Copy Markdown
Contributor

Hello, @adisuissa , I agree all you said. It's not the perfect design and have obvious limit. But the design is not introduced by this PR. This PR's target also is not to provides a better design. The target here is only try to fix an existing bug of current implementation to make it works a little better.

Because this design (canonical xds and updateOnDemand()) is here for a while, and works for a long time. It's not perfect and may in flawed direction, I agree. But I think we still could to fix it.

We still could to construct our new on demand solution based on xdstp by create subscription for every new resource (like the new ondemand cds). But at same, to continuously evolve the canonical xDS is harmless anyway if it could meet our users's requirements.

This PR is only a fix and will make the canonical xDS easier to support delta/ondemand (sure, under you refferred limit). It won't block the developement of better design with xdstp and it's another scope's discussion.

My reading of this PR, and specifically the part that adds append(const absl::flat_hash_set<std::string>& resources) is that it makes the issue worse. After adding this, migrating the code to a different design that decouples things more cleanly would be more costly. Am I reading this incorrectly?

@wbpcode

wbpcode commented Jul 31, 2026 •

Copy link
Copy Markdown
Member Author

@adisuissa

I see the disagreement now. Hmmm, I personally think this PR didn't change existing design but a bug fix only. It should won't actually make thing worse because we have provided the update() there and append() here is actually sub scope of the update().

Note there have been updateResourceInterest() and requestOnDemandUpdate() which will actually be used by the developers. The append() and update() are mainly internal APIs at implementation level and the PR is mainly a bug fix to the requestOnDemandUpdate() implementation.

So, I think it won't make the migrating the code to a different design easier, but also won't make it much more harder because main cost should already have been introduced before because the update(), updateResourceInterest() and requestOnDemandUpdate().

Or could you explain a little more in details about the cost because I didn't aware that. 🙇


BTW, I agree per resource/glob per subscription is more clear and addressed the limit you referred in the #46216 (comment). But I inclined to use that new design (per resource/glob per subscription) only for the xdstp and keep the canonical xDS works in the existing way for a while because the existing solution is lighter/simple to use and no users complain about the limits for now.

@wbpcode

wbpcode commented Jul 31, 2026 •

Copy link
Copy Markdown
Member Author

Also related to istio/istio#60149.

Once we fixed this bug, it would be super easy to support on demand cluster discovery with existing canonical CDS directly (not the ODCDS, but pure CDS). And the Istio could support on demand cluster discovery in a much more easier way.

@wbpcode

wbpcode commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

/retest

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

I spoke offline with @wbpcode and (paging all of this back in after a few years) the useful context here is the existing subscription : resource mapping for on-demand in the various DSes.

For now, just focusing on the bug fix, the issue is that VHDS and ODCDS (non-xdstp) already use a single Subscription for multiple resources. It seems reasonable to make small changes to fix the issue there around resource update rather than move to a per-resource subscription for ODCDS. VHDS already worked before (via hacks) and ODCDS is related in a sense to a glob CDS (which naturally would have a single subscription).

The discussion is really around ODCDS, which is a special on-demand CDS due to this glob/singleton duality of CDS (LDS would have a similar situation if it were on-demand).

I agree with @adisuissa on a single subscription for multiple resources having limitations (e.g. around missing resource handling). It might make sense to either move to per-resource subscriptions outside the bug fix or to enrich the subscription API for this further.

* For legacy VHDS, should an xDS resource name be treated as <namespace>/<resource name>? This is
* incompatible with the use of xdstp:// naming.
*/
bool use_namespace_matching_{};

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.

As discussed offline, it might make review easier to separate this from the bug fix part. If the only consumer of the pattern based matching for now is VHDS, it seems there is less of an acute need to go making major changes here. I agree that is what is there today is a hack and could be done more cleanly, but it seems unrelated to the CDS portion where the bug exists.

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.

Yeah. I will split it out.

// watch-map routing (so the response is delivered to our callbacks) and the subscription sent to
// the management server (so it is fetched). Without the watch-map update, a resource that was not
// named at start() time would match no watch and its update would be silently dropped.
watch_->append(for_update);

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.

This seems the crux of the PR; would it work to refocus the PR around the bug fix and moving the non-xdstp parts of ODCDS to a single subscription model with multiple watched resources?

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.

Yeah. This is the core. And actually this is a fixed version of the previous grpc_mux_->requestOnDemandUpdate(type_url_, for_update);.

We removed the broken requestOnDemandUpdate and use the append to do the correct things.

@adisuissa

Copy link
Copy Markdown
Contributor

FWIW, for singleton (named) resources we had a similar problem with OD-CDS, and this was solved by using a manager for these resources (see #40988 where the singleton manager was added and #41174 where the same subscription manager was used for non-xDSTP over ADS subscriptions).

IMHO, and looking at the current design, going in a direction which adds another internal update will cause more confusion later on and increase tech-debt.
A similar problem also appeared earlier (see Subscription, and specifically the updateResourceInterest() that is no longer used, and requestOnDemandUpdate() that was introduced and invoked ENVOY_BUG in a filesystem, although it should probably try to fetch the resource).
It would be good to decouple the Subscription and the underlying config-source, and keep the interface between them lean.

I'm not against the proposed change, but I believe it will need to be cleaned up later.


IMO the real problem with VHDS, which is not directly related with this change, is due to three features that currently only exist in VHDS:

  1. Having a wildcard and singleton subscriptions on the same stream (OD-CDS has it).
  2. Having multiple subscribing sources for the wildcard VHDS subscriptions (CDS has only one for the wildcard - the ClusterManager).
  3. Using aliases.

These cause some subtle issues, such as: when two listeners use OD-VHDS, and they also must use wildcard VHDS, how would the config-source type know whether a received VHDS resource is for an on-demand-request of a specific listener or for a wildcard update that needs to be sent to the 2 listeners. I think this is a flaw in the design that stems from the question of "what should a wildcard subscription retrieve", and I'm not sure how to solve this problem without substantially impacting the current way the VHDS protocol is implemented.

@htuch

htuch commented Aug 6, 2026

Copy link
Copy Markdown
Member

Regarding the concerns around per-resource subscription overhead vs. shared subscriptions, I ran some experiments with Claude Code to dig into this. The net result is that there is ~600 bytes additional memory usage when adding a subscription to the baseline per-resource tracking overhead of ~350 bytes. There are definitely opportunities to reduce that overhead further, e.g. 72 bytes of the overhead are stats which could arguably be coarser in situations like ODCDS. There are also some benefits we win from the overhead, as @adisuissa points out, the per-resource timer is something you probably want anyway.

Realistically when we're dealing with xDS resource subscriptions the resource itself typically has a non-trivial memory resource costs. If we take the 47 KB Cluster size from

EXPECT_MEMORY_LE(m_per_cluster, 47500); // Round up to allow platform variations.
, we're arguing over a pretty tiny ~1-1.5% memory overhead for the subscription, part of which is paying for something we want, and part of which is optimizable.

So, I'm inclined to not view per-resource subscriptions as prohibitively costly or wasteful.

@wbpcode

wbpcode commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

After RDS warming work is done. I will back to refactor the PR to use a per subscription-per-resource version.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions Bot added the stale stalebot believes this issue/PR has not been touched recently label Sep 10, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions Bot closed this Sep 17, 2026
@wbpcode wbpcode reopened this Sep 17, 2026
@wbpcode

wbpcode commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

Is thinking should pick this up again because I haven't figured out a way to migrate the VHDS and deprecate the requestOnDemandUpdate.
Said.

@github-actions github-actions Bot removed the stale stalebot believes this issue/PR has not been touched recently label Sep 17, 2026
@wbpcode
wbpcode marked this pull request as ready for review September 27, 2026 15:38
@wbpcode

wbpcode commented Sep 27, 2026 •

Copy link
Copy Markdown
Member Author

per-subscription-per-resource is great design for resource types like RouteConfiguration, Cluster, Secret and so on. Their consumer will process the resource one by one And I also think it is fine to use per-subscription-per-resource if possible. But it's not friendly for resources whose consumer will need to rebuild an aggregated output from scratch, like VHDS. For example, if there are 10 virtual hosts in same discovery responses, with the per-subscription-per-resource, we will rebuild the whole route table 10 times continuously.
Today, virtual hosts works with a tricky namespace matching. But for any out-of-tree code who may use the requestOnDemandUpdate() method, it is broken.

So, I guess we still need to fix the bug to make the requestOnDemandUpdate() feature self works correctly. If we can figure out a better solution in the future, I am happy to refactor and remove whole requestOnDemandUpdate. In the AI's age, refactor and clean up is easy task anyway. But before we can actually deprecate and remove the requestOnDemandUpdate, we should not ignore its bug.

cc @htuch @botengyao

@htuch

htuch commented Oct 2, 2026

Copy link
Copy Markdown
Member

I guess I'm still not convinced that per-subscription abstraction is wrong, since the VHDS example just points to naive control flow; the VHDS code should be doing some coalescing across update scopes. But in any case, I think this is all beyond the scope of this PR, which is to fix a real problem in ODCDS without boiling the ocean.

I kind of feel a bit differently these days about tech debt as complex subsystems such as the GrpcMux and its in-treee consumers are more malleable. I just worry if you are taking a hard dependency out-of-tree and consider this a one-way door vs. two-way door.

So, architecturally, as a bug fix, if we still consider this a two way door, I think we should just merge this.

One thing I'd open up here, because I do think we want to do some extensive surgery on GrpcMux in the future, is how this and other parts of the GrpcMux architecutre can be safely changed at scale. What are your thoughts on us being able to build confidence in any major refactoring in the future? I don't trust existing tests, as Hyrum's Law has likely set in at this point.

@wdauchy

wdauchy commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

what is the status on this PR?

@htuch
htuch merged commit 4aaa0d2 into envoyproxy:main Oct 6, 2026
25 checks passed
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]>
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.

on_demand HTTP filter: on-demand CDS response for a second distinct cluster is silently dropped on an already-started subscription

7 participants