GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-116008: Aquire TState and StopTheWorld in faulthandler_user by sergey-miryanov · Pull Request #141267 · python/cpython

Conversation

@sergey-miryanov

@sergey-miryanov sergey-miryanov commented Nov 8, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Trying to be a bit safer for non-fatal signals

  • Issue: Segfault in faulthandler signal handler with threads #116008

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sergey-miryanov added 2 commits November 8, 2025 16:02
@sergey-miryanov
Acquire tstate and stop the world in faulthandler_user
7ed2b6b
@sergey-miryanov
Fix
c8e89f0
@bedevere-app bedevere-app Bot added the awaiting review label Nov 8, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 8, 2025
Segfault in faulthandler signal handler with threads #116008
Closed
@sergey-miryanov

sergey-miryanov commented Nov 8, 2025

Copy link
Copy Markdown
Contributor Author

@vstinner Could you please take a look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sergey-miryanov
sergey-miryanov requested review from AA-Turner and efimov-mikhail and removed request for AA-Turner November 8, 2025 18:58
@sergey-miryanov

sergey-miryanov commented Nov 8, 2025

Copy link
Copy Markdown
Contributor Author

@AA-Turner sorry, misclick.

AA-Turner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity
ZeroIntensity requested changes Nov 8, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't acquire the GIL or make a stop-the-world pause inside signal handlers, because they're not signal safe. For example, Python could receive the signal while in the middle of a stop-the-world pause, which would deadlock inside the signal handler.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Nov 8, 2025
@bedevere-app

bedevere-app Bot commented Nov 8, 2025

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sergey-miryanov

sergey-miryanov commented Nov 8, 2025

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity If I get you right (feel free to correct me):

  1. _PyThreadState_Attach is not signal-safe. If we call _PyThreadState_Attach from within faulthandler_user then another signal can call faulthandler_user again and this led to undefined state. IIUC, we can handle this with the reentrant flag, as faulthandler_dump_traceback did.
  2. _PyEval_StopTheWorld is not signal-safe too. If we already in the stop-the-world state then calling _PyEval_StopTheWorld again will lead to deadlock on stoptheworld_mutex. And we can't handle this without changing the semantics of _PyEval_StopTheWorld. I don't intend to do this.

Therefore, if we want to safely handle non-fatal signals, then using the signal module seems like the only option. Or leave them as-is.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented Nov 8, 2025

Copy link
Copy Markdown
Member

IIUC, we can handle this with the reentrant flag, as faulthandler_dump_traceback did.

Nope, because _PyThreadState_Attach will also try to acquire locks, leading to a deadlock if they're called under a signal.

I think it would be best to just document that faulthandler sometimes crashes if you mess with it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sergey-miryanov
sergey-miryanov marked this pull request as draft November 9, 2025 19:23
@bedevere-app bedevere-app Bot removed the awaiting changes label Nov 9, 2025
@vstinner

vstinner commented Nov 13, 2025

Copy link
Copy Markdown
Member

We can't acquire the GIL or make a stop-the-world pause inside signal handlers, because they're not signal safe.

I agree. This approach is not safe at all. I suggest closing this PR.

efimov-mikhail reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sergey-miryanov

sergey-miryanov commented Nov 13, 2025

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity @vstinner Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sergey-miryanov sergey-miryanov closed this Nov 13, 2025
@efimov-mikhail
efimov-mikhail removed their request for review November 15, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@sergey-miryanov @ZeroIntensity @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.