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

fixes for python tracebacker segfaults #2621

Open
wants to merge 4 commits into
base: uwsgi-2.0
Choose a base branch
from

Conversation

wynnw
Copy link
Contributor

@wynnw wynnw commented Mar 22, 2024

We've found that the uwsgi build with python 3.11 has a log of segfaults when generating the tracebacks via the tracebacker thread. This is a new implementation for that in python 3.11 that has been much more stable as it avoids using sys._current_frames(), instead using the python thread state object uwsgi already has, and then moves more of the hard work into python code to simplify and make that code safer. Hopefully it's helpful for others.

Wynn Wilkes and others added 4 commits March 14, 2024 08:46
- The existing tracebacker is periodically segfaulting on python 3.11.
  This implementation pushes more of the logic into python code,
  leveraging updates to the tracebacker module, so that the c code just
  has to iterate over list of strings returned back. Note that this does
  change the output format of the tracebacker to match the standard
  python format of the traceback.StackSummary.format() method, so anything
  parsing that output that will need to update it's logic to match.
…rsion

- You can now pass a different path for a different python installation.
- If this call fails, we need to release the gil before returning as
  we've obtained it.
…rames() segfaults

- This method is known to behave in strange ways when called from
  multithreaded code, and crashes a lot when doing harakiri tracebacks.
  This new implementation avoids calling sys._current_frames, and
  instead uses the PyThreadState that we already have for the main
  uwsgi worker thread. We get that, then pass that into our python
  function which will build the stack trace string for us. This avoids
  the segfaults and is much more stable than before. It only gets the
  traceback for the main thread which is the uwsgi worker thread, which
  is all we wanted anyway.
xrmx added a commit that referenced this pull request Apr 6, 2024
Cherry pick a couple of commit from #2621
@xrmx
Copy link
Collaborator

xrmx commented Apr 6, 2024

I cherry-picked the two commits in the middle, taking a look at the others will require a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants