From ee5038e7aff42d3b600360b6d674c88d9d0a363e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 26 Jul 2026 01:03:39 +0200 Subject: [PATCH] test: reap the watchdog's sleep in wdkill() Every test left a stray `sleep 300` behind, reparented to PID 1, where it lingered for up to five minutes after the test had finished. wdstart() runs the watchdog in a subshell, so $! is the pid of the subshell, not of the sleep it forks. wdkill() killed the subshell and orphaned the sleep. Kill the child first, killing the subshell puts the sleep beyond the reach of pkill -P. Neither kill is sure to match, and wdkill() runs from the EXIT trap under set -e, so both must tolerate failure. Also return early when wdpid is unset, for failures before wdstart() runs. Signed-off-by: Joachim Wiberg --- test/lib/setup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/lib/setup.sh b/test/lib/setup.sh index 09a57fd1..fb3334ba 100755 --- a/test/lib/setup.sh +++ b/test/lib/setup.sh @@ -255,8 +255,12 @@ wdstart() wdkill() { + [ -n "${wdpid:-}" ] || return 0 + say "Stopping test watchdog, pid $wdpid" - kill -KILL $wdpid + # Reap the sleep first, killing its subshell orphans it to PID 1. + pkill -KILL -P "$wdpid" 2>/dev/null || true + kill -KILL "$wdpid" 2>/dev/null || true } teardown()