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

GH-102397: Fix segfault from race condition in signal handling #102399

Merged
merged 7 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,21 @@ def handler(a, b):
signal.raise_signal(signal.SIGINT)
self.assertTrue(is_ok)

def test__thread_interrupt_main(self):
# See https://github.com/python/cpython/issues/102397
code = """if 1:
import _thread
class Foo():
def __del__(self):
_thread.interrupt_main()

x = Foo()
"""

rc, out, err = assert_python_ok('-c', code)
self.assertIn(b'OSError: Signal 2 ignored due to race condition', err)



class PidfdSignalTest(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix segfault from race condition in signal handling during garbage collection.
Patch by Kumar Aditya.
4 changes: 4 additions & 0 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ get_signal_state(PyObject *module)
static inline int
compare_handler(PyObject *func, PyObject *dfl_ign_handler)
{
// See https://github.com/python/cpython/pull/102399
if (func == NULL || dfl_ign_handler == NULL) {
kumaraditya303 marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}
assert(PyLong_CheckExact(dfl_ign_handler));
if (!PyLong_CheckExact(func)) {
return 0;
Expand Down