Skip to content

fix(xds): unwedge ODCDS after a demand-set shrink and stop expiring in-use upstreams (#682) - #691

Merged
bpalermo merged 3 commits into
mainfrom
fix/682-odcds-stall-and-ttl-touch
Sep 5, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/682-odcds-stall-and-ttl-touch

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

The stall: root cause

The ODCDS catch-all resolves its cluster from the request :authority
(onDemandClusterHeader = ":authority" in agent/internal/xds/proxy/route.go), so a
client dialing a service on a non-80 port makes the on_demand filter ask for a cluster
named <fqdn>:<port> — echo.aether-test.aether.internal:18081.

For every non-default port that name is a real per-port cluster. For the default
port it was nothing at all: buildHTTPEndpointBuckets (agent/internal/xds/cache/cluster.go)
explicitly skips the default port (if p == defaultPort { continue }) and the traffic rides
the portless <fqdn> cluster, whose vhost carries both the portless and the :defaultPort
domain. So an on-demand request for a default-port authority named a cluster the agent
could never publish.

That is not merely a slow cold path, it is a permanent wedge. go-control-plane's wildcard
delta branch (pkg/cache/v3/delta.go, createDeltaResponse) only lists a name in
removed_resources if it had previously returned it, so the agent never told Envoy the
name did not exist either. Envoy's DeltaSubscriptionState therefore parked
echo…:18081 in requested_resource_state_ as waiting for server and
updateSubscriptionInterest deduped every later on-demand subscribe for it. While the
service was in the dependency set nobody noticed — its vhost matched the :18081 domain and
the catch-all was never reached. The moment the demand set shrank and the vhost went away,
every request fell to the catch-all, and no ODCDS request ever reached the agent again.

That is exactly what the logs show: cm odcds: … timed out repeating for 5m10s with no
observed undeclared upstream (ODCDS miss) line on the agent side for the whole outage, then
the ADS stream reset at 00:50:36.363Z rebuilding the subscription state, and the agent
logging the miss 0.4s later at 00:50:36.729Z. The stream reset was the only recovery path.

Two sentences: the on-demand cluster name for a default-port authority
(<fqdn>:<defaultPort>) was never published — only the portless <fqdn> was — so ODCDS for
it could never be satisfied; and because go-control-plane never emits a removal for a name it
never returned, Envoy kept that name subscribed as "waiting for server" forever and deduped
every re-subscribe, so once the demand-set shrink took the service's vhost away, no ODCDS
request reached the agent again and the authority stayed dead until the ADS stream reset.

Commit 1 — the stall

Publish a default-port alias cluster <fqdn>:<defaultPort> alongside the portless one
(buildDefaultPortAliasLocked), so every mesh authority the catch-all can produce for an
in-scope service resolves to a real cluster and an ODCDS miss is answered by the very next
snapshot push. The alias shares the default cluster's bare-service EDS (same endpoints, SAN
pinning and SNI) and carries no vhost of its own — the default entry's vhost already
claims the <fqdn>:<port> domain and a second vhost with that domain would be a
duplicate-domain RDS reject. Node proxies only: the edge serves an explicit exposed set with
no ODCDS catch-all. retainAbsentClustersLocked no longer synthesizes an empty load
assignment for an entry that never published one, so the alias leaves no orphan CLA during
the retention grace.

Reproduction test

TestODCDS_DefaultPortAuthorityIsAnsweredInOnePush
(agent/internal/xds/cache/odcds_test.go): warm aether-test/echo on its default port
18081 → assert the published snapshot carries both echo.aether-test.aether.internal and
…:18081 → let the observed dependency age out, prune, reload → assert both are gone →
issue one on-demand observation and one reload → assert …:18081 is back in the
published snapshot. Verified failing on the pre-fix tree:

map[string]types.Resource{"echo.aether-test.aether.internal":…}
  does not contain "echo.aether-test.aether.internal:18081"

TestLoadClustersFromRegistry_MultiPort previously asserted the absence of a default-port
cluster ("no spurious :8080") — that assertion encoded the bug, so it now asserts the alias's
shape instead (right EDS name, no vhost, no second CLA, maps back to the service key).

Commit 2 — the TTL

Design choice

The observed TTL was documented as an idle timeout but behaved as a hard lifetime: it is
refreshed only by ObserveDependency, which is only reached on an ODCDS request, and an ODCDS
request only happens on a miss — once the cluster is warm the service's own vhost carries
the traffic and the on_demand filter is never reached again. "Treat every ODCDS request as a
touch" is already what the code does; it is a no-op because the requests stop coming.

So the fix needed a real use signal, and the candidates were weighed as follows:

  • A per-cluster request/stream stat. The honest answer, but the agent makes zero Envoy
    admin calls by policy, and access logs, tracing and aether_stats all go straight to the
    collector — nothing per-request reaches the agent today. Getting one means wiring LRS
    (load_stats_config in the proxy bootstrap), i.e. a chart change; out of scope here, and
    worth its own issue if the demand set ever needs finer accounting.
  • Health-check membership gauges. Not available — the agent stopped reading Envoy admin
    entirely (admin-probe elimination).
  • "Referenced by a live route/host in the snapshot." Circular: an observed dependency's
    vhost exists because it is in the dependency set, so this would make observed deps
    immortal and delete demand scoping.
  • Chosen: the node proxy's LIVE named on-demand subscriptions. Envoy's on_demand filter
    subscribes to a cluster name by name when a request needs it and holds that subscription for
    the life of the stream, so a service with a live named subscription is one the proxy is still
    routing to. It is free (the agent already sees every delta request), and it is not
    circular — it is an explicit named subscription created from real demand, not the wildcard
    CDS subscription that covers everything the agent pushes anyway.

Subscriptions are tracked per delta stream by the ODCDS observer
(resource_names_subscribe / resource_names_unsubscribe) and dropped wholesale on
OnDeltaStreamClosed. An observed dependency backed by one is refreshed rather than
expired, in both places expiry happens: the periodic prune and the memoized read-time
wall-clock check in populateObservedDepsLocked — without the latter the entry would still
leave the served set (and its cluster the snapshot) in the up-to-60s window between crossing
the TTL and the next prune tick, which is the very drop this exists to prevent.

This is correctness, not just latency: dropping a still-subscribed cluster is unrecoverable
for exactly the reason in the root cause above. Genuinely idle upstreams still expire — no
traffic means no live subscription once the stream turns over (proxy restart, hot restart,
agent roll), and expired observed upstreams fires exactly as before. Only the catalog-gated
names are pinned, so a ghost service can never hold a dependency open.

Tests

  • TestObservedDependency_LiveOnDemandSubscriptionSurvivesTTL — continuous use across four
    TTL windows keeps the entry, checked both between prune ticks (read-time expiry) and after
    each prune; then the stream closes and the entry ages out normally.
  • TestObservedDependency_UnsubscribeReleasesTheTTLExemption — one authority spelling
    released while another still holds it; both released, it expires.
  • TestOnDemandObserver_TracksLiveSubscriptionsForTTLExemption
    (agent/internal/xds/server/odcds_test.go) — the observer wiring: the <fqdn>:<port>
    authority maps to the bare service key, subscribe records the pin, unsubscribe and stream
    close release it, and a catalog miss is never pinned.

Both new behaviours were verified failing on a tree with the respective fix stubbed out.

Validating on talos

No chart change; ship the agent image and:

  1. Pick a node with no local replica of a service under continuous prober load —
    echo runs on w02/w04/w05, so w01 and w03 are the pair.
  2. Shrink the demand set the cheap way (the reproduction from the grade comment): delete the
    k6 DaemonSet, or scale a workload with no local replica on that node to 0 and back.
  3. Watch the proxy on w01/w03: cm odcds: on-demand discovery for cluster echo.aether-test.aether.internal:18081 timed out must not appear.
  4. Watch the prober: aether_probe_requests_total{tier="mesh_dns",result="http_error"} on
    w01/w03 must stay flat across the shrink (the 2026-09-05 teardown produced 133 and 134
    respectively).
  5. For the TTL half, leave a node unrolled for >1h15m with continuous traffic to a
    demand-scoped upstream and confirm no expired observed upstreams /
    service left dependency set line fires for it while the proxy stream stays up.

Not covered here (from the issue's acceptance list): the soak variant that runs ≥1h15m
without an agent roll, and the prober-tier per-node http_error burst alert — both belong in
the harness and the GitOps repo respectively.

Closes #682

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits September 5, 2026 10:02
…tream (#682)

The ODCDS catch-all resolves its cluster from the request :authority
(cluster_header ":authority"), so a client dialing a service on a non-80
port makes the on_demand filter ask for a cluster named "<fqdn>:<port>".
For every NON-default port that name is a real per-port cluster. For the
DEFAULT port it was nothing at all: buildHTTPEndpointBuckets deliberately
skips the default port and the traffic rides the portless "<fqdn>" cluster,
so an on-demand request for a default-port authority named a cluster the
agent could never publish.

That is not merely a slow cold path, it is a permanent wedge.
go-control-plane only lists a name in a wildcard delta response's
removed_resources if it had previously RETURNED it, so the agent never told
Envoy the name did not exist either. Envoy parked it in its delta
subscription state as "waiting for server" and deduped every later
on-demand subscribe for it, so once the service left the dependency set and
its vhost disappeared, no ODCDS request ever reached the agent again: every
request to that authority failed until the ADS stream reset (~5 minutes
in vivo, and the agent logged no "observed undeclared upstream" line for
the whole outage because it never saw a request).

Publish a default-port alias cluster "<fqdn>:<defaultPort>" alongside the
portless one, so every mesh authority the catch-all can produce for an
in-scope service resolves to a real cluster and an ODCDS miss is answered
by the very next snapshot push. The alias shares the default cluster's
bare-service EDS (same endpoints, SAN pinning and SNI) and carries no vhost
of its own — the default entry's vhost already claims the "<fqdn>:<port>"
domain, and a second vhost with that domain would be a duplicate-domain RDS
reject. Node proxies only: the edge serves an explicit exposed set with no
ODCDS catch-all. The retention path no longer synthesizes an empty load
assignment for an entry that never published one, so the alias does not
leave an orphan CLA behind during the grace window.

TestODCDS_DefaultPortAuthorityIsAnsweredInOnePush is the regression test:
warm the service, expire it out of the demand set, drop its clusters, then
assert one on-demand observation plus one reload puts the requested
authority back in the published snapshot. It fails without the alias.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…iss (#682)

The observed-dependency TTL was documented as an IDLE timeout but behaved as
a hard lifetime. It was refreshed only by ObserveDependency, which is only
reached on an ODCDS request, and an ODCDS request only happens on a MISS:
once the cluster is warm the service's own vhost carries the traffic and the
on_demand filter is never reached again. A node serving a cross-node
upstream at 25 rps therefore dropped it, on purpose, exactly one hour after
it first asked for it — and then had to re-discover it.

Track the node proxy's LIVE on-demand cluster subscriptions instead, and
treat them as the observed-use signal. Envoy's on_demand filter subscribes
to a cluster name by name when a request needs it and holds that
subscription for the life of the stream, so a service with a live named
subscription is one the proxy is still routing to. The subscriptions are
recorded per delta stream by the ODCDS observer (subscribe/unsubscribe), and
dropped wholesale when the stream closes.

An observed dependency backed by one is refreshed rather than expired, in
both places expiry happens: the periodic prune AND the memoized, read-time
wall-clock check in populateObservedDepsLocked (without the latter the entry
would still leave the served set — and its cluster the snapshot — in the
window between crossing the TTL and the next prune tick).

Why this signal and not a traffic stat: the agent makes zero Envoy admin
calls by policy, and access logs, tracing and aether_stats all go straight
to the collector, so no per-request signal reaches the agent today. A true
per-cluster request counter would mean wiring LRS, which needs a proxy
bootstrap (chart) change. The named on-demand subscription is the one
demand signal the agent already receives, it costs nothing, and it is not
circular: it is an EXPLICIT named subscription the on_demand filter creates
from real demand, not the wildcard CDS subscription that covers everything
the agent pushes anyway.

Correctness, not just latency: dropping a still-subscribed cluster is
unrecoverable. Envoy keeps a removed on-demand name in its delta
subscription state as "waiting for server" and dedupes every later
subscribe for it, so no ODCDS request comes back to re-warm it until the ADS
stream resets. Genuinely idle upstreams still expire — no traffic means no
live subscription once the stream turns over, and `expired observed
upstreams` fires exactly as before.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit cc44d69 into main Sep 5, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/682-odcds-stall-and-ttl-touch branch September 5, 2026 13:23
bpalermo added a commit that referenced this pull request Sep 5, 2026
… demand set on a fresh xDS stream (#682) (#698)

* fix(xds): publish the ODCDS alias for the service's mesh port(s), not the registry endpoint port (#682)

#691 published a cold-path alias cluster "<fqdn>:<port>" so the ODCDS
catch-all's cluster_header ":authority" always names a cluster the agent can
actually publish. It derived that port from endpoints[0].GetPort() — the
REGISTRY endpoint port, which is the APPLICATION port
(endpoint.aether.io/port, default 8080). That is not the port a client dials.

Mesh DNS answers a portless A record for the mesh VIP Service, and every mesh
VIP Service advertises exactly one port: meshconst.ProxyOutboundPort (18081),
synthesized by the registrar's Service generator (MeshPort), matched by the
CNI's capture dport rule and by the cap_http route domains. So the authority
the catch-all sees in production is "<fqdn>:18081" — never the app port —
while the alias #691 published was "<fqdn>:8080".

Deployment validation on talos-main (rev194, 2026-09-05) confirmed it: the
only port-suffixed echo cluster present on a node was
echo.aether-test.aether.internal:8080, and no ":18081" cluster existed
anywhere in the fleet — the exact name that stalled for 5m10s
("cm odcds: on-demand discovery for cluster
echo.aether-test.aether.internal:18081 timed out"). The demand-set-shrink test
passed only because #691's TTL exemption kept echo in the dependency set, so
the ":18081" path was never exercised.

Publish an alias for every port an ODCDS authority can legitimately carry that
has no per-port cluster of its own: the mesh port AND the default/application
port (the default entry's vhost claims the latter as a host-match domain, so a
client dialing it must find a cluster too). A port that IS a real advertised
port keeps its own port-filtered per-port cluster — the whole-service alias
never shadows it. Order is deterministic (mesh port first) because map order
is protocol-visible (#135).

TestODCDS_DefaultPortAuthorityIsAnsweredInOnePush now covers both spellings;
the new "mesh Service port differs from the app port" case reproduces
production (app port 8080, dialed port 18081) and fails on the pre-fix tree
with exactly the deployment symptom:

  map[...]{"echo.aether-test.aether.internal", "…:8080"}
    does not contain "echo.aether-test.aether.internal:18081"

TestLoadClustersFromRegistry_MultiPort gains the mesh-port alias assertions,
and TestLoadClustersFromRegistry_MeshPortServedAsRealPort pins the
no-shadowing rule.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* fix(xds): answer the first ODCDS miss on a fresh agent without waiting for a periodic tick (#682)

Deployment validation of #691 on talos-main (rev194, 2026-09-05) found a ~20s
echo outage after every agent restart on the nodes with no local replica:

  w01: CNI conflist re-assert loop started 13:34:46.317Z
       observed undeclared upstream (ODCDS miss) echo   13:35:05.052Z  (+19s)
  w03: 13:35:11.650Z -> 13:35:31.669Z                                  (+20s)

with prober http_error +130 (w01) / +127 (w03) inside the window, then flat,
and the AetherProberHTTPErrorBurst alert firing and resolving.

The agent is not slow. Its xDS socket was accepting 1.8s after the anchor
(13:34:48.125Z); PreListen did not stall (no "registry watch cache not complete
in time", no registry error), the catalog was healthy (no "rejecting on-demand
request for unknown service"), and no TTL expiry fired. The access logs pin the
outage precisely: exactly 133 x 503 cluster_not_found/NC per node, echo only
(uds-echo and uds-cr-echo served 200 throughout), 10 rps to zero at 13:34:51 and
back at 13:35:05, request durations capped at 2003ms — the on_demand filter's
2s timeout, ~7 rounds of it. So Envoy WAS trying, and the agent's
onDeltaRequest callback saw nothing for 14.05s (w01) / 14.67s (w03).

Mechanism: the observed half of the dependency set is process-local memory, so
a restarted agent's first snapshot legitimately drops every ODCDS-acquired
upstream — which is meant to cost one round trip, except a reconnecting Envoy
never re-asks. markStreamFresh() puts every requested resource back into
"waiting for server" and CLEARS the pending-add set, and the first request of
the new stream carries initial_resource_versions only for resources it HOLDS
plus resource_names_subscribe only for names added since. A name it is still
waiting on is in NEITHER field, and updateSubscriptionInterest dedupes every
later re-subscribe for a name already in requested_resource_state_. Nothing
reaches the new agent until Envoy's 15s init-fetch timeout tears that state
down and the next request re-subscribes from scratch — hence 14-15s, and hence
the agent logging nothing at all for the whole outage.

The evidence the agent was ignoring is in the same handshake:
initial_resource_versions is the proxy stating, in the protocol, exactly which
clusters it is still running on. Re-seed the node dependency set from it on the
first request of every delta CDS stream (resumeHeldClusters), so the demand set
is recovered BEFORE the first snapshot push and the upstream never leaves the
snapshot at all.

Restored entries are ordinary TTL'd observations, not live-subscription pins:
an upstream the proxy has stopped using still ages out, so demand scoping still
shrinks after a restart. They are also not counted as ODCDS misses — the proxy
is not asking for something new, the agent is recovering demand it had already
granted, and counting them would drown the miss metric (the signal to promote
an upstream to an annotation) in one burst per restart. Only plain mesh service
clusters are accepted, "<svc>.<ns>.<domain>" with an optional ":<port>" suffix:
per-pod app_/health_ clusters, the "tcp:" floor clusters (a lenient match would
mint keys like "ns/tcp:svc") and the passthrough cluster are not demand-set
entries, and a held name whose service has left the catalog is skipped
silently rather than counted as a rejection.

Tests: TestOnDemandObserver_ResumesHeldClustersOnAFreshStream (the reconnect
handshake with NO named subscribe at all, plus the name filtering and the
no-pin rule), TestOnDemandObserver_ResumeIsIdempotentAndFirstRequestOnly, and
TestRestoreDependency_AnsweredInTheFirstPushAndStillDecays (the requested
authority is in the FIRST push after a restart, and still decays). All three
fail with the resume pass stubbed out.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* feat(agent): count TTL-exempted in-use upstreams (#682)

#691 stopped expiring an observed dependency the node's proxy still holds a
live on-demand subscription for. The exemption's entire effect is that nothing
happens — no "expired observed upstreams", no cluster drop, no ODCDS re-warm —
and its only trace was a Debug line, so the deployment validator had no way to
tell a working exemption from a demand set that simply never aged.

Add aether.agent.upstreams.ttl_refreshed, incremented per exempted entry per
prune pass alongside the existing aether.agent.upstreams.* instruments, and
nil-receiver-safe like the rest of cachemetrics (a no-op for n <= 0, so a prune
pass that exempted nothing records nothing). Raise the accompanying log to Info
for the same reason: it fires at most once per prune tick and only when an entry
actually crossed its TTL.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

---------

Co-authored-by: Claude Fable 5.1 <[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

1 participant