-
Notifications
You must be signed in to change notification settings - Fork 783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix allow_threads segfault #2952
Conversation
Thank you very much for debugging this, a clear explanation and I agree with the proposed fix! Let's get this out as a patch release. Please can you add a newsfragment as The test failure looks like a race. I think what is likely happening is that the new test you have added is writing an object into the pool during the I think the assert!(!POOL.pointer_ops.lock().0.contains(&obj.as_ptr()));
assert!(!POOL.pointer_ops.lock().1.contains(&obj.as_ptr())); Finally, can you please update the test // Returning from allow_threads doesn't clear the pool That comment is now clearly wrong, so I think the |
@@ -478,6 +478,8 @@ impl<'py> Python<'py> { | |||
gil::GIL_COUNT.with(|c| c.set(self.count)); | |||
unsafe { | |||
ffi::PyEval_RestoreThread(self.tstate); | |||
// Update counts of PyObjects / Py that were cloned or dropped during `f`. | |||
gil::POOL.update_counts(Python::assume_gil_acquired()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we should package up RestoreGuard
in mod gil
to centralize the usage of Save/RestoreThread
, accessing GIL_COUNT
and calling update_counts
in that module. (I suspect that having this in separate modules, i.e. making GIL_COUNT
a pub(crate)
item, might have been the root cause of this slipping in.)
Thanks for the feedback. I've added a newsfragment and made the proposed test modifications. I see there are a couple other As for packaging up |
Thanks! I'm going to force-push here to squash. The @adamreichold - I agree with the idea of adding an abstraction layer, however it's fine IMO to not do it in this fix. I've opened #2969 for one of us to remember to do this later. |
5ca6b8f
to
83f5fa2
Compare
bors r+ |
Build succeeded: |
Please see the corresponding issue #2951 for details. This PR adds the failing test from the issue and then a fix for it. The fix simply calls
ReferencePool::update_counts
at the end ofallow_threads
to ensure objects aren't accidentally deleted too soon.