Skip to content

Agent DaemonSet roll drops pre-existing pods' per-pod Envoy listeners (heals only on pod roll) #261

Closed

Description

@bpalermo

Summary

After a full agent DaemonSet roll (e.g. an agent upgrade), pre-existing (long-lived) pods lose their per-pod Envoy listeners — outbound 127.0.0.1:18081 (egress) and inbound :15008 — and stay broken until those pods are themselves rolled. Connectivity does not self-heal.

Reproduction (talos-main, 2026-06-22, during the 0.18.0 deploy)

  1. Deploy a chart rev that rolls the agent DaemonSet (binary changed).
  2. After the agents roll, test a 17h-old workload:
    • client → 127.0.0.1:18081 (node egress) → exit 7 / connection refused (the pod's egress listener is gone).
    • edge → backend pod (:15008) → 503 (the backend's inbound listener is gone).
    • Reproduced consistently across retries; backends themselves were 1/1 Running and healthy.
  3. kubectl rollout restart deploy/{client,echo,svc-1,svc-2} → immediately healed (node-mesh 200 on the first try post-roll; edge path routing green).

Impact

An agent upgrade silently breaks mesh connectivity for every existing workload until each is rolled. That's a serious operational regression — agent rolls should be transparent to running pods.

Likely mechanism (to confirm)

On agent restart, LoadListenersFromStorage rebuilds the per-pod listeners from local storage and republishes the snapshot to the (still-running) node Envoy. Candidates for why pre-existing pods drop out:

  • The fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245 netns guard (LoadListenersFromStorage skips pods where netnsExists(netns) is false) false-positiving on live pods from the freshly-restarted agent's mount view.
  • A storage-reload gap (CachedLocalStorage rehydration missing pods at startup).
  • The republished snapshot being incomplete, so Envoy removes the absent per-pod listeners.

Related

  • Same class as the earlier prober connection_error degradation (a long-lived prober pod lost its egress listener; rolling healed it) — this is the clean, reproducible version, tied to agent rolls.
  • Touches agent/internal/xds/cache/listener.go (LoadListenersFromStorage), the fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245 guard, and agent/pkg/storage.

🤖 Generated with Claude Code

Activity

  1. bpalermo commented on Jun 22, 2026

    @bpalermo
    OwnerAuthor

    Root-caused — it's stale local storage, not proxy re-bind

    Used the prober DaemonSet as a live canary (long-lived, not rolled by 0.18.0): after the roll it's at 100% connection_error. Inspected worker-01:

    • The agent at restart loaded count:8 pods and generated the full listener set (17) — no skipping pod with missing network namespace (netns-guard skips = 0). So the agent is NOT dropping listeners.
    • BUT it generated the prober listener for prober-vhbp8 (netns 834daf…) — yesterday's prober pod, long deleted. The live prober on this node is prober-k7vsm (1/1, 10.244.3.177), which is absent from the agent's storage entirely (0 references).
    • So the proxy bound outbound_http_prober-vhbp8 into the dead pod's netns; the live prober-k7vsm got no listener → 127.0.0.1:18081 refused → connection_error. Rolling the pod issues a fresh CNI ADD → heals.

    Mechanism (two desyncs)

    1. Missed CNI DEL for prober-vhbp8 → its storage file and its netns bind-mount pin (/run/aether/netns/834daf…) linger. os.Stat on the lingering pin succeeds, so netnsExists returns true and the fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245 stale-netns guard/sweep does NOT prune it — the guard is fooled by a lingering pin (it checks netns presence, not pod presence).
    2. Missed CNI ADD for the replacement prober-k7vsm → the live pod never entered storage.

    The agent restart (0.18.0 roll) merely re-applied this already-stale storage; the desync predates the roll. Nothing reconciles local storage vs the node's actual pods — the ghost sweep reconciles registry endpoints vs storage, but storage is the corrupted source of truth here.

    Fix direction

    Reconcile the agent's local storage against the node's actual Kubernetes pods (by pod UID/name — the agent already queries node metadata), not against netns presence:

    • Prune storage entries whose pod no longer exists (regardless of a lingering netns pin) → drops the dead-netns listener.
    • Surface (and ideally recover) live pods missing from storage (missed ADD) — at minimum log/metric; full recovery needs the CNI data, so a pod-UID-keyed reconcile + re-request, or alerting for operator action.
    • Decouple the prune decision from netnsExists (fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245), which a lingering bind-mount defeats.

    Files: agent/internal/cni/server/ghostsweep.go (extend to a pod-existence reconcile), agent/internal/xds/cache/listener.go (#245 guard), agent/pkg/storage.

  2. bpalermo commented on Jun 22, 2026

    @bpalermo
    OwnerAuthor

    Storage-mechanism findings + concrete fix design

    agent/storage/local.go (CachedLocalStorage): one <containerID>.json file per pod, atomic writes, loadAll rehydrates the whole dir into the in-memory cache at Initialize. Sound — so a running pod missing from storage means its <containerID>.json is absent on disk (its CNI ADD never durably wrote, or the file was removed), and a ghost means a stale file lingers.

    The two desync classes (both present on worker-01)

    1. Ghost with a lingering netns pin (prober-vhbp8): missed CNI DEL left both the storage file and the /run/aether/netns/834daf… bind-mount pin. netnsExists (os.Stat) succeeds on the lingering pin → the fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245 stale-netns prune can't catch it (it keys on netns presence, not pod presence). The agent keeps emitting a listener bound to a dead netns (also a latent fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245-segfault if that pin ever points at a truly-gone netns).
    2. Missing live pod (prober-k7vsm): its file is absent → a missed/lost CNI ADD (or it was pruned and never re-added). The pod runs with no listener → connection_error, and never self-heals.

    Why nothing fixes it today

    The ghost sweep reconciles registry endpoints ↔ local storage, never local storage ↔ the node's actual pods. And the #245 prune trusts netnsExists, which a lingering bind-mount defeats (and which could conversely over-prune a live pod whose stored netns path went stale after a sandbox change).

    Fix design (no new RBAC — the agent already has pods: list/get/watch + a k8sClient)

    Extend sweepGhostEndpoints (or a sibling loop) to reconcile storage against the node's real pods:

    • List pods on this node (s.k8sClient.List, fieldSelector spec.nodeName=s.nodeName).
    • Prune ghosts by pod-existence: for each stored CNIPod, if no live pod matches its namespace/name, RemoveResource + RemovePod — regardless of netnsExists. This removes lingering-pin ghosts like vhbp8 (fixes the dead-netns listener + the segfault risk).
    • Surface missing ADDs: for each live mesh-managed pod (has IP, aether.io/managed) on the node with no matching stored entry, emit a metric + log + Event. The agent can't synthesize the CNI data (netns/IPs) to self-heal, so this is operator/auto-roll signal — but at least it's no longer silent.
    • Keep fix(agent,proxy): prune stale-netns pods + supervisor crash-fast-fail #245's netns-gone check as a fast belt for the segfault path, but make pod-existence the authoritative prune signal.

    Separately worth chasing for prevention: why k7vsm's CNI ADD didn't durably land (lost write vs over-prune) — but the reconcile cures the desync class regardless, and the startup taint (separate PR) closes the cold-start window.

  3. bpalermo commented on Jun 22, 2026

    @bpalermo
    OwnerAuthor

    Prevention root cause: CNI DEL doesn't guarantee the storage delete (context-propagation + ordering)

    AddPod and RemovePod are asymmetric, and the asymmetry produces ghosts:

    AddPod (robust):

    • storage.AddResource is first (pod.go:74) — durable before anything fallible.
    • RegisterEndpoint failure is tolerated (pod.go:99-103: logs "reconciliation sweep will retry", no early return).
    • So once an ADD proceeds past the store, storage always has the pod.

    RemovePod (the bug):

    • UnregisterEndpoints(unregCtx) (pod.go:182) runs on the request context and is fatal — on error it returns at line 186.
    • snapshotCache.RemovePod(xdsCtx) (198) is likewise fatal (returns at 202).
    • storage.RemoveResource (206) is last.

    So if the request ctx is canceled (the plugin's delTimeout, kubelet cancel, or agent SIGTERM — common/xds/server.go GracefulStop falls back to a forced Stop() after ShutdownTimeout), or the registrar is briefly unavailable (we saw UnregisterEndpoints fail with context canceled during the registrar roll), the handler returns before RemoveResource → the storage file and its netns pin linger → exactly the prober-vhbp8 ghost (and a latent #245 dead-netns segfault). RemoveResource itself ignores ctx, but the handler never reaches it.

    Fix (matches the asymmetry)

    Make DEL mirror ADD — storage delete first / guaranteed, registry+listener best-effort:

    1. In RemovePod, remove local storage first (or unconditionally, e.g. defer), on a detached/background context, so the durable local truth is cleared regardless of request-ctx cancellation or registrar availability.
    2. Tolerate UnregisterEndpoints failure (log + continue, like ADD tolerates RegisterEndpoint) — the ghost sweep reconciles the registry endpoint; it must not abort the local delete.
    3. Mind the lifecycleMu window (pod.go:174-177) when reordering — keep the liveness loop from resurrecting a half-removed pod.

    This guarantees the storage delete on shutdown / cancellation / registrar churn, eliminating the ghost class at the source. The storage↔pods reconcile (prior comment) remains the cure for any residual desync (and the missing-ADD case); the startup taint closes the cold-start window. Three layers: guaranteed delete (prevention) + reconcile (cure) + taint (cold-start).

  4. bpalermo commented on Jun 22, 2026

    @bpalermo
    OwnerAuthor

    Resolved — prevention + cure shipped and validated on talos-main

    Root cause: the agent's local storage desynced from reality — ghosts from missed CNI DELs whose netns pin lingered (so the #245 netns guard couldn't catch them → dead-netns listeners → connection_error + latent segfault), and missing pods from lost CNI ADDs (running pods with no listener, never self-healing).

    Three layers:

    1. Prevention — fix(cni): guarantee the local storage delete on CNI DEL (#261) #262 (merged): RemovePod guarantees the storage delete (detached ctx, storage-first, best-effort/bounded unregister), so a canceled ctx / SIGTERM / rolling registrar can't leave a ghost.
    2. Cure — feat(cni): reconcile local storage against the node's actual pods (#261) #264 (merged): the ghost sweep reconciles storage against the node's actual pods — prunes orphans by pod-existence (catches lingering-pin ghosts) and surfaces missed ADDs via metric. No new RBAC.
    3. Cold-start — feat(agent): Cilium-style startup taint to gate pods on CNI readiness #263 (open): Cilium-style startup taint so workloads wait off a node until its CNI is serving.

    e2e on talos-main (rev 22, 0.18.0-44bc8dd)

    The reconcile cleaned the real degraded state: 26 orphans pruned (incl. the root-caused prober-vhbp8, netns 834daf…) and 116 missed-ADDs surfaced (incl. prober-k7vsm). After healing rolls the sweep converged (0/0), the prober SLI returned to 100% success (was 100% connection_error), node-mesh + edge both 200, and a post-roll sweep showed 0 new orphans (confirming the guaranteed delete). New metrics ghost_sweep.orphans_pruned / ghost_sweep.missing_storage are flowing.

    Closing as resolved. The cold-start prevention layer continues in #263.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions