From 79e6587d8ad677f1f3ac89a2839139df96dc7c21 Mon Sep 17 00:00:00 2001 From: Snider Date: Mon, 9 Mar 2026 15:10:48 +0000 Subject: [PATCH] fix: poll process via Signal(0) in stopDaemon for PID reuse safety Co-Authored-By: Virgil --- cmd/service/cmd.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/service/cmd.go b/cmd/service/cmd.go index cf7b99b..2f56e78 100644 --- a/cmd/service/cmd.go +++ b/cmd/service/cmd.go @@ -175,9 +175,13 @@ func stopDaemon(reg *process.Registry, code, daemon string) error { } // Wait for process to exit, escalate to SIGKILL after 30s. + // Poll the process directly via Signal(0) rather than relying on + // the daemon to self-unregister, which avoids PID reuse issues. deadline := time.Now().Add(30 * time.Second) for time.Now().Before(deadline) { - if _, still := reg.Get(code, daemon); !still { + if err := proc.Signal(syscall.Signal(0)); err != nil { + // Process is gone. + _ = reg.Unregister(code, daemon) cli.LogInfo(fmt.Sprintf("Stopped %s/%s (PID %d)", code, daemon, entry.PID)) return nil }