Skip to content

PyMutex failure in parking_lot.c on Windows during interpreter shutdown #135099

Closed
@colesbury

Description

@colesbury

Bug report

Bug description:

Fatal Python error: _PySemaphore_PlatformWait: unexpected error from semaphore: 4294967295 (error: 6)
Python runtime state: finalizing (tstate=0x6aa6c460)

Thread 0x00001360 (most recent call first):
  <no Python frame>
Windows fatal exception: code 0x80000003

Current thread 0x00001360 (most recent call first):
  <no Python frame>

Current thread's C stack trace (most recent call first):
  <cannot get C stack on this system>

4294967295 is the -1 return code from WaitForMultipleObjects. Error code 6 is ERROR_INVALID_HANDLE.

I'm pretty sure that the _PyOS_SigintEvent() handle is getting closed concurrently with the mutex wait.

HANDLE sigint_event = _PyOS_SigintEvent();
HANDLE handles[2] = { sema->platform_sem, sigint_event };
DWORD count = sigint_event != NULL ? 2 : 1;
wait = WaitForMultipleObjects(count, handles, FALSE, millis);
if (wait == WAIT_OBJECT_0) {
res = Py_PARK_OK;
}
else if (wait == WAIT_OBJECT_0 + 1) {
ResetEvent(sigint_event);
res = Py_PARK_INTR;
}
else if (wait == WAIT_TIMEOUT) {
res = Py_PARK_TIMEOUT;
}
else {
_Py_FatalErrorFormat(__func__,
"unexpected error from semaphore: %u (error: %u)",
wait, GetLastError());
}

Seen in https://github.com/python/cpython/actions/runs/15423887404/job/43405853684 at the end of running test_decorators.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions