Skip to content

🐛 fix(win32): reclaim a soft lock from an exited holder - #874

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
nk-batman21:fix/win32-exited-holder-probe
Oct 28, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
nk-batman21:fix/win32-exited-holder-probe

Conversation

@nk-batman21

@nk-batman21 nk-batman21 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, a soft lock left behind by a crashed worker was never reclaimed while any other process still held a handle to that worker. The usual case is the supervisor that started it: multiprocessing.Process keeps the child's handle after join() until close() or garbage collection, and subprocess.Popen keeps it after wait(). A supervisor that kept its worker objects and then took the lock waited forever with the default timeout=-1, while Linux and macOS reclaimed the same marker at once. 🪟 Such a lock is now reclaimed as soon as the holder has exited, whoever still references it.

The owner probe opened the recorded PID with OpenProcess and read any successful open as a live process, but an exited process stays openable for as long as a handle to it exists, and its creation time still matches the marker's start token. The probe now also waits on that handle with a zero timeout: a process object is signaled once the process terminates, so only that signaled state counts as gone, and a timed-out or failed wait still counts as alive. Windows does not reuse a PID while a handle to it is open, so the stricter verdict adds no recycling risk, and the lock keeps breaking a marker only on proof of death.

…eeps it open

process_alive() read any successful OpenProcess as a live process, but an
exited process stays openable while any handle to it is open, such as a
parent's subprocess.Popen after wait() or multiprocessing.Process after
join(). A soft lock left by a crashed holder was then never reclaimed on
Windows while its parent kept that object, and acquire() with the default
timeout=-1 waited forever.

Wait on the handle with a zero timeout and treat the process as gone only
once it is signaled. A failed wait still reads as alive.
@gaborbernat gaborbernat changed the title fix(win32): treat an exited soft-lock holder as gone while a handle keeps it open 🐛 fix(win32): reclaim a soft lock from an exited holder Oct 28, 2026
@gaborbernat gaborbernat reopened this Oct 28, 2026
@gaborbernat gaborbernat reopened this Oct 28, 2026
@gaborbernat
gaborbernat merged commit cb18d9e into tox-dev:main Oct 28, 2026
72 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants