Skip to content

Commit

Permalink
fix: Prefer os.Process.Signal to syscall.Kill
Browse files Browse the repository at this point in the history
This protects us from a potential (but rare) race condition where

1. the process we are trying to signal terminates of its own accord
2. its PID gets reaped in the os.Process.Wait call
3. a new process with the same PID gets spawned

before our signal actually gets sent.

This is achieved by using the higher-level os.Process API directly, which
has some synchronization to prevent os.Process.Wait and os.Process.Signal
from racing.
  • Loading branch information
anrddh committed Aug 19, 2024
1 parent 771066f commit a1e532e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/command/stopper_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *CmdWrapper) Stop(sig int, parentOnly bool) error {
Msg("Stop Unix process.")

if parentOnly {
return syscall.Kill(c.Pid(), syscall.Signal(sig))
return c.cmd.Process.Signal(syscall.Signal(sig))
}

pgid, err := syscall.Getpgid(c.Pid())
Expand Down

0 comments on commit a1e532e

Please sign in to comment.