-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[BUG]: Creation of py::tuple or py::list causes a crash with policy py::call_guard<py::gil_scoped_release>() on Ubuntu 22 #4015
Comments
@ylegoc Are you able find the specific commit which broke things? Also does it still crash when using master? |
I removed the word regression from the title because this is a form of regression. That is why it seems to come from the gcc version but not from a bad commit. |
We are fine on GCC 11 from AlmaLinux 9. Are you sure you don't have a race condition that happens to not trigger on the "old" system? I'd recommend trying our test suite on your system. |
I run the test suite on my system and it succeeds. Then I modified test_pytypes.cpp: And test_pytypes.py: And it's crashing in the get_tuple_gil() call with a segmentation fault. However maybe this is not a good practice and I should release the gil only for non pybind11 code? |
FWIW : I tried g++-11 + Ubuntu 20.04 (focal) and no segfault. edit: but: I'm not sure it's safe to call py::make_tuple with a released GIL actually. that looks to be the issue eventually ? |
You can’t modify the Python memory model with the GIL released. That’s why there’s a GIL. Making a tuple very much modifies Python memory. The crash is random and could be compiler dependent, it’s UB. |
Required prerequisites
Problem description
After some tests on my Ubuntu 22, I remarked that pybind11 was crashing at the creation of a py::tuple or py::list object in my project.
Calling the function test() defined below causes a segmentation fault.
Crashes on:
No crash on:
By looking deeper into the problem, I found out:
Using the policy py::call_guard<py::gil_scoped_release>() causes the crash. Without the policy it works well.
I tried different compilation options that all resulted in a crash.
To summarize:
The creation of a py::tuple or py::list object causes a crash on my Ubuntu 22 (gcc 11.2.0, Intel(R) Core(TM) i5-8500) with the policy py::call_guard<py::gil_scoped_release>().
Reproducible example code
The text was updated successfully, but these errors were encountered: