Skip to content

Possible race condition in signal handling #102397

Description

@kumaraditya303

The following code segfaults the interpreter on Linux. Tested on current main.

importgcimport_threadgc.set_threshold(1, 0, 0)
defcb(*args):
_thread.interrupt_main()
gc.callbacks.append(cb)
defgen():
yield1g=gen()
g.__next__()
Exception ignored in: <function cb at 0x7f7f4f6fe200>Traceback (most recent call last): File "/workspaces/cpython/main.py", line 7, in cb _thread.interrupt_main()KeyboardInterrupt: Exception ignored in: <function cb at 0x7f7f4f6fe200>Traceback (most recent call last): File "/workspaces/cpython/main.py", line 7, in cb _thread.interrupt_main()KeyboardInterrupt: Exception ignored in: <function cb at 0x7f7f4f6fe200>Traceback (most recent call last): File "/workspaces/cpython/main.py", line 7, in cb _thread.interrupt_main()KeyboardInterrupt: Exception ignored in: <function cb at 0x7f7f4f6fe200>Traceback (most recent call last): File "/workspaces/cpython/main.py", line 7, in cb _thread.interrupt_main()KeyboardInterrupt: Segmentation fault (core dumped)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errortype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions