GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — Fix `call_soon_threadsafe()` racing with `close()` on free-threaded Python by maartenbreddels · Pull Request #789 · MagicStack/uvloop ConversationFixes #788. On a free-threaded build, The fixThe loop gets a The lock is not reentrant, so no code that can allocate Python objects runs under it. I first tried
TestsNew test: I ran these tests on 3.14t, 3.14, and 3.9, all pass: The standalone repro from the issue, on 3.14t: three 20-second runs and one 60-second run, 0 crashes and 0 A GC re-entry check (a Cost, on an M-series Mac:
Disclosure: the analysis, the fix, and the tests were written with Claude Code, and reviewed by three AI reviewers. The crash comes from our own production-like load tests.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionscall_soon_threadsafe() checks _closed, appends to _ready and then calls handler_async.send(). On a free-threaded build another thread can run close() in between: it closes handler_async and sets it to None, so the poster segfaults in send(). The same race also makes close() fail with "deque mutated during iteration" or "new callbacks were queued during loop closing". With the GIL the method runs as one step, so this did not happen. A critical section on the loop is not enough: the deque append can block on the deque's own lock, and that suspends the outer critical section. A PyMutex stays held while the thread blocks. The mutex is not reentrant, so nothing that can start a GC runs under it: a finalizer could post to the same loop and deadlock. That is why the closed-loop error is raised after the lock is released. Co-Authored-By: Claude Opus 5.5 <[email protected]>
maartenbreddels
marked this pull request as ready for review
Vizonex
approved these changes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense to me as to why this would be in place. I'll have to think about implementing this on winloop's end if needed. There seems to be a workflow broken but it's not the library's fault so I approve of this PR.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
@maartenbreddels In the meantime I've added this bugfix on winloop's side Vizonex/Winloop#189 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Segfault incall_soon_threadsafe() when another thread closes the loop (free-threaded Python)
There was an error while loading. Please reload this page.