Use try_lock in py_os_after_fork_child#7178
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughCentralized environment-mapping→dict conversion into Changes
Sequence Diagram(s)sequenceDiagram
participant Parent
participant Fork as fork()
participant Child
participant Lock as after_fork_lock
participant Callbacks
Parent->>Fork: fork()
Fork-->>Child: child process starts
Child->>Lock: try_lock() (non-blocking)
alt lock acquired
Lock-->>Child: guard
else lock busy
Child->>Lock: force_unlock state
Child->>Lock: lock() (blocking)
Lock-->>Child: guard
end
Child->>Callbacks: clone callback list from guard
Child->>Callbacks: execute after-fork callbacks
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
35748aa to
064ed0c
Compare
February 17, 2026 11:08
064ed0c to
bde518f
Compare
February 17, 2026 14:00
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/vm/src/stdlib/posix.rs`:
- Around line 719-727: The unsafe recovery using
vm.state.after_forkers_child.force_unlock() should be removed; instead, when
vm.state.after_forkers_child.try_lock() returns None in the forked child, treat
callbacks as optional and skip them (e.g., return an empty clone/Vec or no-op)
rather than forcing the mutex open. Update the match on
vm.state.after_forkers_child.try_lock() so the None branch does not call unsafe
force_unlock() but returns a safe empty value or sentinel so downstream code
that uses after_forkers_child simply sees "no callbacks" and proceeds safely.
Sorry, something went wrong.
after_forkers_child.lock() can deadlock in the forked child if another thread held the mutex at the time of fork. Use try_lock and skip at-fork callbacks when the lock is unavailable, matching the pattern used in after_fork_child for thread_handles.
bde518f to
f5d24b0
Compare
February 17, 2026 16:11
e81a0fc
into
RustPython:main
Feb 17, 2026
after_forkers_child.lock() can deadlock in the forked child if another thread held the mutex at the time of fork. Use try_lock and skip at-fork callbacks when the lock is unavailable, matching the pattern used in after_fork_child for thread_handles.
after_forkers_child.lock() can deadlock in the forked child if another thread held the mutex at the time of fork. Use try_lock and skip at-fork callbacks when the lock is unavailable, matching the pattern used in after_fork_child for thread_handles.
Summary by CodeRabbit
Bug Fixes
Refactor