asyncio.subprocess.Process
race condition kills an unrelated process on Unix
#127049
Labels
asyncio.subprocess.Process
race condition kills an unrelated process on Unix
#127049
Bug report
Bug description:
On non-Windows platforms, there appears to be a race condition around asyncio's PID lifetime management that results in
asyncio.subprocess.Process.[send_signal | terminate | kill]
signaling the wrong process, by callingkill
on an already-freed PID. I observed this behavior occurring in the wild and I suspect this race condition was the underlying cause.A reproducer that consistently hits the race condition on 3.13.0, 3.14.0a1, main:
This bisects to GH-121126. GH-121126 fixed GH-87744 (where asyncio (on
_ThreadedChildWatcher
only) andPopen
racedwaitpid
calls) by removing thewaitpid
fromProcess.send_signal
. The problem with this is that nowProcess.send_signal
callskill
on a PID that may have already been freed by asyncio (on either_PidfdChildWatcher
or_ThreadedChildWatcher
). GH-82811 is analogous; IIUC GH-121126 inadvertently regressed GH-82811 except for processes spawned viaasyncio
rather than those spawned viasubprocess
.CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
Linked PRs
asyncio.subprocess.Process
race condition killing an unrelated process on Unix #127051The text was updated successfully, but these errors were encountered: