[BUG] Unchecked errors can potentially swallow signals/other exceptions
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
context
I'm trying to figure out why CTRL-C isn't working in my Linux application.
I'm periodically checking PyErr_CheckSignals in my inner loop in the main thread and it never seems to be firing -- but python is clearly seeing it at some point, as when I close the UI window the python code throws the KeyboardInterrupt and everything crashes because a thread tries to take the GIL during shutdown.
That is not what this issue is about, but it's useful context -- I'm sure I'm not doing something right, just need to figure out the right way to do it.
issue
However, in my search the following two links come up:
- https://bugs.python.org/issue35459 (PR @ https://github.com/python/cpython/pull/11112)
- https://stackoverflow.com/a/25877795/5483904
Basically, PyDict_Get/Set/Del can potentially swallow errors (including signals!) if the WithError variants aren't used. There are a few places in pybind11 where the less safe versions of these functions are used, which could be potentially contributing to my problem. It seems the WithError variants were introduced in Python 3, so to switch to these would require a Python 2.7 shim.
Has anyone else been contemplating this? There aren't that many places where errors aren't checked in pybind11, so it probably wouldn't be terrible to find them all and squash em. Ideally it would be nice if we could add some kind of linter to make sure nobody introduces such things in the future, but that seems hard.
Reproducible example code
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the pybind11 source for PyDict_Get, PyDict_Set, and PyDict_Del uses, then compare each call with the corresponding WithError variant. Check how Python 2.7 compatibility is handled before determining the required scope. Done means the relevant unchecked uses are addressed without breaking supported Python versions, with coverage for the affected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100