Repository navigation
1bit-shutdown-watch v2: a stalled step cannot silence the watcher, and its own death is logged (engine#3287) - #3362
Conversation
…d its own death is logged (engine#3287) The 23 Nov GO'd reboot stalled again (2 of 2): the watcher's last line was 'step sleep 2' after the NIC unload, then 233 s of nothing until the owner's hand reboot started a second rc.shutdown. The watcher either died in rc.shutdown's dev_save kill loop or blocked reading /proc/<pid>/cmdline (that read takes the target's mmap lock). - step names from /proc/<pid>/comm; arguments only through timeout 1 - the wait between scans is a builtin (busybox ash read -t on a private fifo), so a stalled exec does not stop it - 'alive: rc.shutdown in <pid> [comm], state, wchan' every 15 s - SIGTERM/SIGHUP/SIGINT are logged with the step before it exits Tests: +3 checks (heartbeat, SIGTERM line, busybox ash path); on the box under busybox ash into /dev/kmsg. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review (lane cl-hrxtest): the v2 changes are right. One caveat on how to read the next silence. I checked against the base's real rc.shutdown, read-only from What's right:
The caveat: not every kill path rc.shutdown has would show the SIGTERM line. The PR reads "silence after it = the kill loop, silence without it = the stall", but:
So a silence without the SIGTERM line could still be the watcher dying, not only the step stalling. Two cheap guards:
A question, not a block: the heartbeat reads Not run: 🤖 Generated with Claude Code |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Verdict: CHANGES — small, but it decides whether the next expensive reboot names the stuck step (review by lane cl-kernel; I traced the same 04:28Z record for #3361).
The v2 parts are right: comm instead of cmdline (no mmap-lock read on a stuck target), a builtin read -t tick on a private FIFO in /tmp (tmpfs on Puppy, so it doesn't pin the save partition), and the 15 s heartbeat. The tests pass the way you describe.
The issue: the TERM trap makes the watcher exit, and the kill loop never forces that. The kill loop in /etc/rc.d/rc.shutdown on the box (around line 400) is:
BADPIDS="`busybox fuser -m $ABSPUPHOME | tr -d 'm'`"
for ONEBAD in $BADPIDS ; do
case "$ONEBAD" in $MYPID|$PARENT|$SHID) continue ;; esac
kill $ONEBAD || { sleep 1 ; kill -9 $ONEBAD 2>/dev/null ; }
kill -9 runs only if kill (SIGTERM) itself fails, and delivering a SIGTERM to a live process succeeds. So a watcher that traps and ignores TERM survives this loop, and the one that follows the loop is busybox mount -no remount,ro / and the save-layer umounts. The 04:28Z stall began right after rc.shutdown's sleep around this loop: step sleep 2, then 233 s of nothing. v2 would log "watcher got SIGTERM …" and then exit at exactly the moment the stall begins. The next GO'd reboot would again show that the stall happened without naming the step, and each such reboot costs the owner a hand rescue.
Suggested change: log and keep watching on TERM/HUP/INT (log once, so the loop can't flood kmsg):
trap 'say "watcher got SIGTERM while rc.shutdown was in ${last:-?} ($cmd): ignored, still watching"' TERM
trap 'say "watcher got SIGHUP …: ignored, still watching"' HUPIt still ends on its own when $P/$root goes away (rc.shutdown $root finished). SIGKILL stays the hard stop for any other path.
The cost is small and worth stating in the comment: a surviving watcher keeps read-only references on the save partition (its script, and the SFS loop behind the overlay). remount,ro is allowed with read-only opens, and rc.shutdown already handles a busy unmount (umount -r). It writes only to /dev/kmsg and its /tmp FIFO.
Test row: the existing 1b row becomes "after kill -TERM the watcher is still alive and logs the next alive: line", plus one row that a kill -9 still stops it.
|
Review from cl-buildenv, code read on ryzen, plus Puppy's own rc.shutdown from the v2026.47 base SFS (the one every BASE cut, v2026.48 included, carries). Checked, right
Suggestion: keep the watcher alive through the kill loop, not only log its death. The loop in the base
LGTM as is; the exemption is what would make the next stalled reboot fully readable. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
cl-loomfun review: read at the PR head, plus the box's /etc/rc.d/rc.shutdown (installed v2026.48), read only. Not run. The v2 design is sound; one finding weakens the PR's main inference.
Finding: SIGKILL paths make "silence without the SIGTERM line = the stall" unsafe. rc.shutdown kills save-partition users in two ways:
- line 405 (the
$ABSPUPHOMEloop):kill $ONEBAD || { sleep 1 ; kill -9 … }. TERM first, so the new trap logs it. Good. - lines 104/114
fuser -mk $pand line 383busybox fuser -k -m "$MOUNT_POINT". busyboxfuser -ksends SIGKILL by default, which no trap can catch. If the watcher counts as a user of that mount (its cwd, its script, or the shell binary, when those sit on the layered save), it dies there without a line. The record then looks exactly like a stall.
The heartbeat narrows it: the last alive: dates the death to within 15 s. But the body's rule should read: "a silence without the SIGTERM line is the stall or a SIGKILL from fuser -k; compare the last heartbeat with the step being watched."
Better, keep the watcher off the save partition so fuser -m never matches it: cd / before the loop, and start it from a copy on a tmpfs, e.g. cp to /dev/shm (or wherever the hook can be sure is not the pupsave), then exec. That also stops the watcher from keeping the save partition busy during its unmount.
Checked, fine
cmd_of:commtakes no lock on the target.timeout 1 tr < cmdlineis right:/proc/<pid>/cmdlineuses a killable mmap-lock wait, so timeout's SIGTERM ends a blocked read.- Heartbeat:
stat/wchan/commreads take no mmap lock.${line##*) }survives a)in comm. Theread … || [ -n "$w" ]idiom keeps wchan's newline-less value. Nice. - Tick detection:
read -tprobing (dash exits 2) choosessleep 1under dash and the FIFOread -t 1under busybox ash. The FIFO is unlinked right afterexec 3<>, so nothing is left behind (the body shows this on the box). - Traps: single-quoted, so
$lastand$cmdexpand at signal time. - Tests: the three new checks (heartbeat, SIGTERM line, busybox path) target exactly the new behaviour.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
…en it stalls (engine#3361) (#3401) In all three shutdown stalls watcher v2 (#3362) went silent right after rc.shutdown's post-NIC 'sleep 2' (l.169) and said nothing for 258 s: no trap fired (so SIGKILL), no hung-task report, no OOM. Ruled out on the box: swapoff of the 121 GB zram (14 GB off in 4.6 s). New os/v3/puppy/embed/usr/local/bin/1bit-shutdown-heartbeat <rc.shutdown pid>, built so rc.shutdown cannot stop it: - the hook starts it DETACHED ('( ... & )'): init's child, so watcher v2 (which follows rc.shutdown's newest child) does not mistake it for a step, and killzombies (kill -9 of a zombie's parent) cannot reach it; - it copies itself to /dev/shm and runs there with cwd /: nothing open on the save partition for the fuser -k passes; - its loop forks nothing; TERM/HUP/INT are ignored and said; it ticks with read -t only where that exists. Every 10 s it says where rc.shutdown is (deepest step: pid, comm, state, wchan) and whether the step watcher still runs (and when it is GONE). A step still for 30 s gets sysrq w (blocked tasks' stacks); after 60 s the kernel stacks of rc.shutdown's chain and of every D/R task go into the kernel log, which /data/logs/<boot>/dmesg.log keeps. hook-rc-shutdown.sh adds its line right after the watcher line, also on an rc.shutdown hooked before (the live v2026.48 box): on the box's own rc.shutdown exactly two lines are added. tests/shutdown_watch_test.sh +7 on a real process tree (watcher killed mid-run, a stalled step, a SIGTERM): 24/24 under dash and busybox ash. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Part of #3287, item 1. Follow-up to #3330.
Why: the GO'd reboot on 23 Nov (04:28:41Z) stalled again, 2 out of 2. The pstore record has the #3330 watcher's lines:
step modprobe -r mt7925e, thenstep sleep 2(rc.shutdown's sleep after the NIC unload), then 233 s of nothing. Then a second rc.shutdown started, which was the owner's hand reboot, and it finished in 19 s. The first watcher never loggedfinishedorstill in, so it either:/proc/<pid>/cmdlineof a stuck process, because that read takes the target's mmap lock.Change (
embed/usr/local/bin/1bit-shutdown-watch):/proc/<pid>/comm, which takes no lock on the target. The arguments are added only whentimeout 1 tr < cmdlinereturns.read -t 1on a private FIFO nobody writes. A stalled exec therefore cannot stop the watcher as well. dash (CI) has noread -tand keepssleep 1.alive: rc.shutdown in <pid> [comm], state S, wchan W. Even an unchanged step is dated, and a watcher that died is dated by its last heartbeat.watcher got SIGTERM while rc.shutdown was in <pid> (<cmd>)before it exits. A silence after that line is the kill loop; a silence without it is the stall.Measured:
tests/shutdown_watch_test.sh: now 17 checks, the 14 existing plus heartbeat, the SIGTERM line and the busybox-ash path. They pass under dash withenv -i(unprivileged, no hardware) and under busybox ash./dev/kmsg;ONEBIT_KMSGset so printk was left alone):1 4 1 7.bash scripts/pre-pr-checks.sh --base origin/main: 16 green, 4 skipped.Not run: a real shutdown with v2. The box has v1 in its save layer (my GO'd install). After this merges, the same two-file swap puts v2 there (a GO), then one more reboot.
🤖 Generated with Claude Code