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

Crash when inspecting frame of other thread in free-threaded build #118680

Open
chgnrdv opened this issue May 7, 2024 · 3 comments
Open

Crash when inspecting frame of other thread in free-threaded build #118680

chgnrdv opened this issue May 7, 2024 · 3 comments
Labels
topic-free-threading type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented May 7, 2024

Crash report

What happened?

Found when playing with #118415 (comment). Appears on both debug and non-debug builds.

import sys
import threading

l = threading._PyRLock()

def f():
    while True:
        with l:
            pass

t = threading.Thread(target=f)
t.start()
while True:
    f = sys._current_frames()[t.ident]
    while f:
        f.f_code
        f = f.f_back

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.0a6+ (heads/main:9fd33af5ac, May 7 2024, 03:18:30) [GCC 10.2.1 20210110]

@chgnrdv chgnrdv added the type-crash A hard crash of the interpreter, possibly with a core dump label May 7, 2024
@savannahostrowski
Copy link
Member

I can't reproduce the crash on a Mac (M3 Pro), in case that's helpful!

@erlend-aasland
Copy link
Contributor

I can repro on a MacBook Pro (M1), using ./configure --disable-gil --with-pydebug && make:

$ ./python.exe ./crash.py
Assertion failed: (frame->frame_obj == NULL), function _PyFrame_MakeAndSetFrameObject, file frame.c, line 48.
[1]    27564 abort      ./python.exe ./crash.py
$ ./python.exe -VV
Python 3.13.0a6+ (heads/main-dirty:d3c7821335, May  7 2024, 09:27:50) [Clang 15.0.0 (clang-1500.3.9.4)]
$ ./python.exe -c "import sys; print(sys._is_gil_enabled())"
False

@colesbury
Copy link
Contributor

Yeah, this function is not thread-safe. We need to figure out what to do about it.

More precisely, the call sys._current_frames() is okay, but accessing other thread's frames while they are running is not thread-safe without the GIL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

5 participants