Description
In #13987, we fixed the race between Wait and Signal where Wait frees the PID in the OS, which can then reuse it before Signal sends a signal to what is now a different process.
The same race applies to Wait + Wait (ignoring pidfd): https://cs.opensource.google/go/go/+/master:src/os/exec_unix.go;l=41-54;drc=dbe2e757bb55f80de1a622da6bd5060e979208d1
In two concurrent calls to Wait, both will see the process as waitable in blockUntilWaitable
. Both then proceed unconditionally to the wait syscall. One of these calls will win and get the wait status. The other, if slow and the OS has reused the PID, will wait on a different process with the same PID.
I believe this race would be fixed by replacing the unconditional setDone
with a compare and swap that bails out if isdone
is already set.
cc @ianlancetaylor @golang/runtime