fix(wake): close fd 9 in the detector's sleep child so a dead detector's lock dies with it #993

Merged
Mos merged 4 commits from fix/966-detector-lock-fd-leak into main 2026-07-31 13:48:34 +00:00
Showing only changes of commit c1954ea2ac - Show all commits
@@ -533,11 +533,13 @@ cmd_run() {
# keeps the single-instance flock (fd 9, taken at exec 9> above) alive after
# the detector parent dies. The lock is non-blocking (`flock -n`, above), so
# for as long as that sleep survives a replacement instance is REFUSED and
# exits rather than queueing. The window is BOUNDED by one poll interval
# (WAKE_DETECTOR_INTERVAL, default 30s): when the orphaned sleep exits the
# last copy of the fd closes and the next start succeeds. The cost is a
# restart window in which every supervisor retry fails — not a lock that
# nothing can ever reclaim.
# exits rather than queueing. This particular hold is BOUNDED by one poll
# interval (WAKE_DETECTOR_INTERVAL, default 30s): when the orphaned sleep
# exits its copy of fd 9 closes, ending this bounded sleep-child hold. It
# does NOT follow that the next start succeeds — other inheritors of fd 9
# (the M1 adapter, M2 sink grandchildren) are outside this patch's scope and
# can keep holding the flock. The cost this removes is a restart window in
# which every supervisor retry fails on the sleep child's account.
# `9>&-` closes ONLY the child's copy — the parent's lock is unaffected.
sleep "$interval" 9>&-
done