-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Prevent internals destruction before all pybind11 types are destroyed #5972
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
base: master
Are you sure you want to change the base?
Conversation
|
@XuehaiPan Is your plan to work on adding a new unit test here after you have the fix? — Short-term the fix is most important, long-term the test will be more important. I could try to use some LLM to generate a new test, based on what you provided under 5958. Do you think that'd be useful? |
|
It might be better to mostly revert #5958 if the behavior it has is not what we want. The problem described is expected (but undesirable) behavior from that PR. It is not a use-after-free. It's also possible for One option is to go back to something more like the first commit on #5958, before I went into releasing internals itself. The original goal of that PR was to get rid of the leaks of the |
|
I think releasing some part of the internal but keeping the internal leaked would be a safest choice. |
@XuehaiPan did you see my question above (https://github.com/pybind/pybind11/pull/5972#issuecomment-3786298624)? Subinterpreter support added a lot of complexity; if we don’t capture these issues in unit tests, pybind11 will regress over time. I’m very skeptical of fixes that don’t start from a failing unit test. |
Those leaks are currently dwarfed by CPython leaks documented here (pure‑C reproducer): Until those are fixed in CPython, or we find a workaround that sidesteps them, the savings from #5958 are marginal. If reverting #5958 is what it takes to ship v3.0.2, that seems like a reasonable short‑term compromise. |
This makes sense to me because most users only use the main interpreter. The leak will be freed anyway on program shutdown, while the correctness is more important.
I am trying to add a repro. It is hard to find a consistent repro for the order bugs since there is no guarantee. |
Description
Fixes https://github.com/pybind/pybind11/pull/5958/changes#r2717645230
Suggested changelog entry:
📚 Documentation preview 📚: https://pybind11--5972.org.readthedocs.build/