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

Py3.12: Getting stack traces can crash the interpreter #1969

Open
jamadden opened this issue Jul 11, 2023 · 1 comment
Open

Py3.12: Getting stack traces can crash the interpreter #1969

jamadden opened this issue Jul 11, 2023 · 1 comment
Labels
Level: help wanted The maintainers could use help Platform: POSIX PyVer: python3 Affects Python 3 Type: Bug Identified as a bug; needs a code change to fix

Comments

@jamadden
Copy link
Member

With the current state of gevent on 3.12b3 (gevent 23.7.0, greenlet 3.0a1), test__util.py crashes the interpreter while executing pure-Python code that calls traceback.format_stack(). This test exercises the format_run_info function, which looks for any reachable greenlet objects (using gc.get_objects()) and prints their stacks, starting with the greenlet.gr_frame frame object.

The crash happens when the traceback code executes f = f.f_back, and the crash is inside PyObject_GetAttr.

This suggests that the frame object is invalid or corrupted, which in turn suggests a greenlet issue, but:

  1. All the other tests for gevent and greenlet pass, so greenlets and frame switching are working; and
  2. Only some greenlets cause this error. Most of them print fine.

Perhaps gc.get_objects is finding greenlets that it shouldn't? Perhaps greenlet needs to be more proactive about setting gr_frame to None?

This has been observed on macOS.

On Linux, instead of crashing, f = f.f_back was producing an AttributeError: dict has no attribute f_back. Not sure how that could happen either baring memory corruption of some sort.

(Windows is not yet testing 3.12, so I don't know what happens there.)

For the release of gevent 23.7.0, I have disabled stack traces for greenlets in util.GreenletTree.__render_tb as a workaround. This is not ideal, obviously.

@jamadden jamadden added Type: Bug Identified as a bug; needs a code change to fix PyVer: python3 Affects Python 3 Platform: POSIX Level: help wanted The maintainers could use help labels Jul 11, 2023
@jamadden
Copy link
Member Author

jamadden commented Sep 8, 2023

This is fixed in the latest greenlet release, I just need to make sure it's re-enabled here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Level: help wanted The maintainers could use help Platform: POSIX PyVer: python3 Affects Python 3 Type: Bug Identified as a bug; needs a code change to fix
Projects
None yet
Development

No branches or pull requests

1 participant