Repository navigation
fix(link): send SIGKILL to a one-route ssh that ignores SIGTERM, keep a stopped one-route child owned until it exits, and fix orphan wording - #8640
Merged
Conversation
…n, and fix orphan wording A one-route spawn whose pidfile write failed left its child unwatched; the next tick sent it SIGTERM, forgot it and removed the pidfile without waiting, so the retry or a reload that gave the link routes could start a tunnel while that ssh was still exiting, and an ssh that ignored SIGTERM was never killed. The spawn now attaches its exit watch before writing the pidfile, and the tick sends SIGTERM once, SIGKILL after 2 s, and keeps the child until its exit is seen; the exit watch then removes the pidfile conditionally, as for any exit. Also: the ENOENT clause of the gained-routes sentence in structure/remote-link.md no longer reads as the adopted child's outcome, the dropStalePidfile and observe-only comments match their callers, and the test file loses its double and trailing blank lines. Refs #8609
… after the grace A stop, reload or reconnect sent a one-route child only SIGTERM and awaited its exit, and the tick that could escalate returned early while that lifecycle work ran, so an ssh that ignored SIGTERM held the lifecycle queue for every link. The tick now sends SIGKILL to a draining child 2 s after its first SIGTERM, keeping a stop time the tick already set. Shutdown clears the timer first and still sends only SIGTERM. Refs #8609
Shutdown cleared the supervisor timer before its stops, and the tick returned at once while stopping, so a child a reload or reconnect was draining, or one shutdown itself stopped, never got its SIGKILL when it ignored SIGTERM. Shutdown now clears the timer after its stops, and the tick sends the drain SIGKILL before its stopping check. Refs #8609
Shutdown now waits for every child stop to settle, so one stop that throws cannot cut another child's drain short, and clears the timer in a finally block, so a failed stop never leaves the interval running. The first failure is still rethrown. Refs #8609
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Contributor
|
✅ Deterministic PR hygiene checks passed. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
3 tasks done
lidge-jun
added a commit
that referenced
this pull request
Nov 13, 2026
One conflict, the import block of src/link/supervisor.ts: dev's "CANDIDATE_KILL_GRACE_MS, createRouteRounds, type LinkRouteStatus" import is kept and this branch's operations-journal import is added after it. The rest of both sides merged on their own: a suspended link whose child is draining is still escalated and forgotten when it exits, and spawnFor then declines it; a revoke's hold-then-stopLink now ends within about 2 s for an ssh that ignores SIGTERM.
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The last follow-up to #8626 (issue #8609), from the final review of that PR.
A failed link's running child was stopped without waiting. A one-route spawn registered its ssh child, wrote the pidfile, and only then attached the exit watch. If the pidfile write failed, the link went to failed while the child kept running unwatched. The next supervisor tick sent it SIGTERM, forgot it, and removed the pidfile naming it without waiting for the exit. Until that ssh actually exited, two things could start past it: the link's retry, or a reload that gave the link routes (it took the no-child path, read ENOENT, and started a round). An ssh that ignored SIGTERM never got SIGKILL and was never watched again.
The spawn now attaches the exit watch before writing the pidfile, as the multi-route spawn already did. For a successful write, only the moment the exit callback is registered moves. The tick sends a failed link's running child SIGTERM once and SIGKILL 2 s later (
CANDIDATE_KILL_GRACE_MS, as for a stopped candidate), and keeps the child until its exit is seen. The exit watch then forgets it and removes the pidfile conditionally, as for any exit. The reducer leaves a failed, not-in-flight state unchanged on an exit, so the retry schedule is the same. Until that exit, neither the retry nor a reload that gives the link routes starts a tunnel: the reload stops the child and settles from the pidfile after the exit (#8626).No stop waits forever on an ssh that ignores SIGTERM. Before, a stop, reload or reconnect sent a one-route child only SIGTERM and then awaited its exit, and the tick, which could have escalated, returned early while that lifecycle work ran. A stubborn ssh therefore held the lifecycle queue for every link. Shutdown cleared the timer before its stops and had the same problem. Now:
stopChildrecords the child it drains, keeping a stop time the tick already set.finallyblock, so a failed stop never leaves the interval running, and still rethrows the first failure.Wording.
structure/remote-link.md, the ENOENT clause of the gained-routes sentence now follows "gets the same watch from its pidfile", so it no longer reads as the adopted child's outcome. The doc also describes the stop and SIGKILL behaviour above.dropStalePidfilecomment names its callers: a process that is gone, one sent SIGTERM at one-route startup, or this process's own child that exited or was stopped.What keeps this inert. Nothing changes for an ssh that exits on SIGTERM within 2 s, which is every ssh in normal operation, or for a one-route spawn whose pidfile write succeeds. Behaviour changes only when a pidfile write fails, when an ssh ignores SIGTERM for 2 s, or when a child's stop throws during shutdown. No configuration or default changes, and
recordInstanceis untouched.Verification
Tests written first in
tests/clients/link-route-supervisor.test.ts. The harness can now make a tunnel'skillthrow and counts timer clears. Withsrc/link/supervisor.tsput back todev(6ee1b91), the final test file gives 74 pass and 7 fail; four of the seven fail by the 5 s test timeout, because the old code never sends SIGKILL and the stop never ends.a one-route tunnel the tick stops after its pidfile write failed is watched until it exits: SIGKILL after the grace, no second tunnel meanwhile: ondev, no SIGKILL.a reload that gives routes while a stopped, unrecorded one-route tunnel is still exiting starts no round until it exits: ondeva probe starts while the old ssh lives.a reload that stops a running child / a child the tick already stopped which ignores SIGTERM sends SIGKILL after the grace: SIGKILL is asserted while the reload is still pending.shutdown during a reload's drain / on its own still sends SIGKILL after the grace to a one-route child that ignores SIGTERM.a shutdown whose stop of one child fails still escalates the other drains and clears its timer.The existing #8626 test of a tick stop whose pidfile removal fails still passes; that removal now happens when the exit is seen.
Commands on the head (exit codes):
TMPDIR=/tmp bun test tests/clients/link-route-supervisor.test.ts tests/clients/link-supervisor.test.ts: 117 pass, 0 fail (exit 0).bun run typecheck: exit 0.bun run privacy:scan: exit 0.bun run structure:check: exit 0.TMPDIR=/tmp bun scripts/test.ts --parallel=2 tests/clients tests/server/link-management-routes.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/ci-structure-gate.test.ts tests/ci-workflows/file-size-ratchet.test.ts(212 files, includingtests/clients/link-boundary.test.ts): 3626 pass, 67 skip, 3 fail (exit 1). The 3 failures are the Rust ocx-child tests (tests/clients/link-ocx-child-e2e.test.ts, two cases, and the Rust case oftests/clients/link-ocx-child-conformance.test.ts). They stop before any test code runs, becausecargoon the build machine has no default rustup toolchain. This branch touches no Rust code.NOT RUN: the full
bun run testsuite (the build machine allows focused files only; CI covers the rest); the three Rust ocx-child tests above (no toolchain); Windows and macOS. The signals go through the same runnerkillthe stopped-candidate path already uses on every platform.Review: four read-only rounds by one independent reviewer (gpt-6.1-terra, xhigh effort), continued across rounds.
Each fix has a test in the list above. Round 4 found no P0–P2 in the whole slice and ran the two supervisor test files on the head (117 pass).
Checklist