Skip to content

feat(proxy-supervisor): Envoy thread-stall sampler to attribute the handoff stalls (#1093) - #1100

Merged
bpalermo merged 3 commits into
mainfrom
fix/1093-handoff-stall
Oct 1, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/1093-handoff-stall

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Refs #1093. This PR adds observability; it is not the fix. The data from the 2026-10-01 soak cannot say why the threads stalled. This PR records that the next time a stall happens.

What the soak data shows (read-only on talos-main)

1. The stall is node-local and is not caused by the handoff. A handoff only makes it worse.

  • Destination-side h3 requests with duration_ms > 500, counted in 30 s buckets over the 8 h window:
    • w04 and w05 have dozens of episodes, including the no-roll window 06:40–08:10.
    • w02 has a few. w01 and w03 have essentially none.
  • They all share one signature: every pod on the node at once shows upstream_service_time of about 1 s to 127.0.0.1:8080. Example: w04 at 06:27:07, 40 lines at 0.5–1 s.
  • The three handoff stalls are the tail of this distribution. Slow lines per bucket: 131 at w04 02:16, 98 at w04 04:17, 120 at w05 05:41.

2. The new epoch's Envoy workers are the threads that stall.

  • envoy_workers_watchdog_miss_total (Envoy counts a miss when a worker goes ≥ 200 ms without a loop iteration) moved only on w04 and w05 during the 8 h. It never moved on w01–w03.
  • At 02:16, envoy_server_worker_{0,3}_watchdog_miss_total of epoch 119 rose between 02:16:45 and 02:16:50. That is exactly the stall window.
  • Request 5c483b89 was received by the w04 source at 46.618. It reached its w02 destination at 49.099 and was served there in 6 ms. So 2.5 s was lost on w04.
  • About 40% of the successor's new h3 upstream connects took 250 ms–2.5 s. Most of the parent's took ≤ 100 ms.

3. The stall is not visible as CPU.

  • Pyroscope (process_cpu) over the stall shows:
    • each Envoy at 0.6–1.1 cores, doing QUIC/UDP I/O and nothing else;
    • the node at about 2.7 of 4 cores;
    • nothing unusual compared with the clean 04:54 handoff on the same node, which drew the same CPU.
  • So the threads were waiting for a CPU, blocked, or descheduled. An on-CPU profile cannot tell which.

Ruled out:

What this PR adds

A thread-stall sampler in the proxy supervisor: agent/internal/proxy/hotrestart/{stallsampler,procstat}.go.

  • It runs every 100 ms (--stall-sample-interval; 0 disables it).
  • It reads /proc/<envoy>/task/<tid>/{schedstat,stat,wchan} for the main thread and the wrk:* threads of every epoch the supervisor runs. It uses no ptrace.
  • Per one-second window it classifies each thread:
    • starved: waiting in the runqueue;
    • blocked: asleep anywhere other than ep_poll, with the wchan named;
    • busy: on a CPU for ≥ 90% of the window.
  • The threshold is --stall-threshold, default 200 ms, which is Envoy's own watchdog miss bound.
  • It logs one envoy thread stall line per epoch per flagged window. The line carries the node's figures for the same second: busy, irq, softirq and steal shares; the irq+softirq share of the hottest CPU; and PSI cpu-some and irq-full.
  • It adds the counter aether.supervisor.envoy_thread_stalls{class}, seeded at 0.
  • There is no chart change. The defaults apply when the flags are absent.
  • Runbook: "A node stalls for seconds during a handoff (proxy: a multi-second node-local stall at the parent's 'closing and draining listeners' during some hot-restart handoffs (1 liveness timeout in the 2026-10-01 soak, not #1085) #1093)".

Proof

  • Unit tests (stallsampler_test.go) run against a fake procfs. They cover:
    • each class, the wchan, D-state sleep, and the node and PSI fields;
    • an idle window that logs nothing while the counter is still seeded;
    • a withheld wchan, which is not counted as a block;
    • a late tick, where windowMs reports the actual span;
    • epochs that come and go;
    • the parsers, using verbatim w04 /proc/stat and PSI lines;
    • a live /proc read.
  • Commands run: bazel test --config=race //agent/internal/proxy/hotrestart:all //agent/internal/supervisorcmd:all, //agent/cmd/proxy-supervisor:deps_test, make gazelle / make format, and lint with fail_on_violation (gocognit ≤ 15 holds).
  • kind (aether-1093, chart from this branch, since deleted):
    • Real Envoy threads idle in ep_poll, as the classifier assumes.
    • About 4 minutes idle plus a full cross-pod hot-restart handoff produced 0 stall lines.
    • A 4–6 s cpu.max throttle of the proxy container logged every thread as starved, with the node quiet:
      envoy thread stall epoch=1 windowMs=4100 threads=["envoy[starved] cpu=8ms runq=3664ms …","wrk:worker_0[starved] cpu=0ms runq=3860ms …",…] nodeBusyPct=7.7 nodePSICPUSomeMs=2923
      
  • Not exercised on kind: the blocked and busy classes. They are covered only by the unit tests.

Talos gate for the main session after deploy

  1. Rolls under load. With k6 at the soak rate, run 6 proxy rolls 12 min apart, plus the 90 min no-roll window.
  2. Wiring. envoy thread-stall sampler running must appear on 5/5 nodes. The aether_supervisor_envoy_thread_stalls_total series must exist on 5/5 nodes (seeded at 0).
  3. Spam bound. On w01–w03 in the no-roll window, there must be ≤ a handful of lines per hour.
  4. Attribution. For every handoff that shows prober timeouts, or > 50 slow destination lines, read the envoy thread stall lines from fork−5 s to parent exit+5 s on that node.
  5. Decision:
    • starved with high nodePSICPUSomeMs: node CPU contention. Find from Pyroscope, node-wide, which processes took the CPU. Fix with proxy CPU priority or QoS, or by spreading the handoff burst.
    • blocked with a wchan: the stall is in that kernel path or lock. Fix it there.
    • busy: use Pyroscope on that worker in that second to find the callback.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits October 1, 2026 11:54
…er a handoff stall is starvation, a block or a busy loop (#1093)

The 2026-10-01 soak's three multi-second handoff stalls (w04 02:16 and
04:17, w05 05:41) cannot be attributed from today's data: Pyroscope is
on-CPU only and showed nothing unusual, Envoy's worker watchdog counted
misses only on w04/w05 but says neither when nor in what, and there is
no per-node CPU/PSI series.

Every 100 ms the supervisor now reads, for the main and wrk:* threads of
each Envoy epoch it runs, /proc/<pid>/task/<tid>/{schedstat,stat,wchan}
(no ptrace) and, per one-second window, classifies a thread as starved
(runqueue wait), blocked (asleep outside ep_poll; wchan named) or busy
(>=90% on a CPU) once it crosses --stall-threshold (200 ms, Envoy's
watchdog miss bound). One "envoy thread stall" line per epoch per
flagged window, with the node's busy/irq/softirq/steal shares, the
hottest CPU's irq+softirq share and PSI cpu-some/irq-full for the same
second, plus aether.supervisor.envoy_thread_stalls{class} seeded at 0.
--stall-sample-interval=0 disables it. No chart change.

Refs #1093

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

1 participant