Repository navigation
feat(node): heartbeat the systemd watchdog from the runtime and test serve-loop starvation - #2145
Conversation
…serve-loop starvation A serve loop that goes around without awaiting holds a tokio worker. Once every worker is held, the node serves nothing, logs nothing and answers no /metrics scrape, but its systemd unit stays `active`, so nothing restarts it. #2133 fixed the sliver-credit loop that did this (#2132). This change makes the failure class recoverable and pins the fixed case. - `systemd_watchdog`: when systemd passes `WATCHDOG_USEC` and `NOTIFY_SOCKET`, a runtime task sends `WATCHDOG=1` every half period. The heartbeat runs on the runtime, so it stops when no worker is free, and systemd restarts the node. No node setting: the unit's `WatchdogSec=` turns it on. Honors `WATCHDOG_PID`; supports path and abstract sockets; the socket is non-blocking so a full queue cannot block a worker. - `a_sliver_voucher_does_not_starve_the_runtime`: runs the #2132 sliver case on a one-worker runtime and fails if a heartbeat task on it stops ticking. It fails in ~2 s against the parent of #2133 (0 ticks) and passes on main. A starved runtime is leaked, not dropped, because the drop would wait forever for the worker to yield. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change is self-contained, matches the stated operational goal, and includes targeted unit/integration coverage; remaining feedback is a minor performance refinement.
Review effort: Lite
Findings: 1
What changed in this PR
This PR adds a systemd watchdog heartbeat that runs on the Tokio runtime so systemd can restart decdn-node when the runtime is wedged (e.g., all workers busy-spinning), and it adds a regression test that detects serve-loop starvation on a single-worker runtime.
Changes:
- Add a
systemd_watchdogmodule that readsWATCHDOG_USEC/NOTIFY_SOCKETand sendsWATCHDOG=1at half-period from a runtime task. - Spawn the watchdog heartbeat at the start of
decdn-nodebring-up to cover initialization and shutdown drain. - Add a loopback regression test that fails if a sliver-voucher scenario causes the runtime heartbeat to stop ticking.
| File | Description |
|---|---|
| crates/node/src/systemd_watchdog.rs | Implements env-parsed watchdog heartbeat + unit tests for parsing and datagram send. |
| crates/node/src/main.rs | Spawns the watchdog heartbeat early in main. |
| crates/node/src/lib.rs | Exposes the new systemd_watchdog module. |
| crates/node/tests/client_loopback.rs | Adds a single-worker starvation regression test keyed to the sliver-voucher case. |
| CHANGELOG.md | Documents the runtime watchdog heartbeat feature and the new regression test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…rtbeat Co-Authored-By: Claude Opus 5.5 <[email protected]>
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 20e9b45 in the Show a line coverage summary of the most impacted files.
Updated |
* feat(decdn_node): enable the systemd watchdog on the node unit decdn-node heartbeats WATCHDOG=1 from its tokio runtime when the unit sets WatchdogSec (decdn/decdn#2145). A node whose runtime workers are all held by work that never yields stops the heartbeat, and systemd restarts it instead of leaving it `active` while it serves nothing. - WatchdogSec={{ decdn_node_watchdog_sec }} (default 60) plus NotifyAccess=main, so systemd accepts the main PID's heartbeat. - AF_UNIX joins RestrictAddressFamilies, since the heartbeat goes over NOTIFY_SOCKET. - decdn_node_watchdog_sec: 0 omits all three, for a binary that predates the heartbeat and would otherwise be killed every period. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(decdn_node): make the systemd watchdog opt-in The role cannot tell whether the binary it installs heartbeats, and a binary that does not is killed every period, so decdn_node_watchdog_sec defaults to 0. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>

Problem
A serve-loop iteration that neither awaits nor makes progress holds a tokio worker. Before #2133, a sliver voucher put
deliverin exactly that state (#2132). Once every worker is held:/metricsscrape;activeand nothing restarts it.#2133 fixed the accounting, and the no-progress guard now fails the stream instead of letting it spin. Two gaps remain:
Fix
crates/node/src/systemd_watchdog.rs: a runtime-liveness heartbeat for the systemd service watchdog.WATCHDOG_USECandNOTIFY_SOCKET, a task on the tokio runtime sendsWATCHDOG=1every half period.Restart=brings it back.WatchdogSec=turns it on and sets the period, and withoutWATCHDOG_USECit never starts.WATCHDOG_PIDand supports both path and abstract (@) sockets. The socket is non-blocking, so a full queue cannot block a worker.mainspawns it first, so it also covers bring-up and shutdown drain.NotifyAccess=mainand allowAF_UNIXinRestrictAddressFamilies.a_sliver_voucher_does_not_starve_the_runtime(crates/node/tests/client_loopback.rs):Considered and left out:
/metricssees the same hang, because that listener runs on the starved runtime.WatchdogSec=is the knob.Verification
5ca3e7f1^, the parent of fix(node): keep a partly paid chunk owed so the serve loop cannot spin (#2132) #2133 (the runtime worker ticked 0 times in 1 s), and passes on main (10/10 stress runs).systemd_watchdogunit tests: env parsing (period, missing or zero values, PID match) and a round trip over a realUnixDatagram.cargo nextest run -p decdn-node: 1270 passed.cargo clippy --all-targets --all-features -D warnings,cargo fmt --checkandcargo doc -D warningsare clean.🤖 Generated with Claude Code