Skip to content
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

Improve the error reporting for inc_ref GIL failures #4427

Merged
merged 5 commits into from Dec 30, 2022

Conversation

EthanSteinberg
Copy link
Collaborator

@EthanSteinberg EthanSteinberg commented Dec 27, 2022

Description

In 2.10.2, we added a new feature to catch UB when inc_ref or dec_ref are called without the GIL. This functionality works great, but the error reporting via an exception is very suboptimal as those exceptions get called in weird environments, triggering weird crashes.

This PR adds some good old-fashioned fprintf statements to help users understand what is going on. I want to use fprintf here because that's generally the most reliable method in all sorts of environments (especially when iostream might not be initialized properly).

Closes #4426

Suggested changelog entry:

Improved error messages when inc_ref/dec_ref are called with an invalid GIL state.

@EthanSteinberg
Copy link
Collaborator Author

@Skylion007 @henryiii I know this sucks, but I think you might want to push this out ASAP given all the issues with 2.10.2

Might be worth rereleasing 2.10.2 with this patch or pushing out 2.10.3

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry a lot of comments, but really only about details. The general approach is great! Thanks again for jumping in making this better.

include/pybind11/pytypes.h Outdated Show resolved Hide resolved
include/pybind11/pytypes.h Outdated Show resolved Hide resolved
include/pybind11/pytypes.h Show resolved Hide resolved
include/pybind11/pytypes.h Show resolved Hide resolved
@rwgk
Copy link
Collaborator

rwgk commented Dec 28, 2022

I don't remember seeing the pypy-3.7 • windows-2022 • x64 CI failure. Rerunning to be sure it's a flake.

@EthanSteinberg
Copy link
Collaborator Author

EthanSteinberg commented Dec 28, 2022

I believe all of the comments are now resolved. Thanks for the feedback and reviews!

docs/advanced/misc.rst Show resolved Hide resolved
docs/advanced/misc.rst Outdated Show resolved Hide resolved
@rwgk
Copy link
Collaborator

rwgk commented Dec 30, 2022

Could someone else please merge this? (@henryiii or @Skylion007)
I only have a very unstable internet connection for the next few days. In case there is something unexpected, I may not be able to respond quickly.

@henryiii henryiii merged commit 60f02f5 into pybind:master Dec 30, 2022
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Dec 30, 2022
@EthanSteinberg EthanSteinberg deleted the better_error_on_gil_error branch December 30, 2022 18:47
rwgk added a commit to google/clif that referenced this pull request Jan 1, 2023
…pointer.

Context:

* pybind/pybind11#4427 (comment)

> I don't think your logic ... is actually correct? I don't think it would handle metaclasses right.

PiperOrigin-RevId: 498690703
henryiii pushed a commit that referenced this pull request Jan 2, 2023
* First

* Fixs

* Improve

* Additional assertions comment

* Improve docs
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST]: Improve error logging with new inc_ref() feature
4 participants