◐ Shell
clean mode source ↗

Fix _at_fork_reinit to write INIT directly instead of calling unlock() by youknowone · Pull Request #7312 · RustPython/RustPython

@youknowone marked this pull request as ready for review

March 2, 2026 11:30

coderabbitai[bot]

unlock() goes through unlock_slow() which accesses parking_lot's
global hash table to unpark waiters. After fork(), this hash table
contains stale entries from dead parent threads, making unlock_slow()
unsafe. Writing INIT directly bypasses parking_lot internals entirely.
The import lock is a ReentrantMutex that was never reinit'd after
fork(). If a parent thread held it during fork, the child would
deadlock on any import. Only reset if the owner is a dead thread;
if the surviving thread held it, normal unlock still works.

coderabbitai[bot]

This was referenced

Mar 3, 2026

youknowone added a commit to youknowone/RustPython that referenced this pull request

Mar 22, 2026
…() (RustPython#7312)

* Fix _at_fork_reinit to write INIT directly instead of calling unlock()

unlock() goes through unlock_slow() which accesses parking_lot's
global hash table to unpark waiters. After fork(), this hash table
contains stale entries from dead parent threads, making unlock_slow()
unsafe. Writing INIT directly bypasses parking_lot internals entirely.

* Add import lock (IMP_LOCK) reinit after fork

The import lock is a ReentrantMutex that was never reinit'd after
fork(). If a parent thread held it during fork, the child would
deadlock on any import. Only reset if the owner is a dead thread;
if the surviving thread held it, normal unlock still works.