Skip to content

gh-158200: Harden faulthandler against freed code metadata - #158202

Open
Alishahryar1 wants to merge 1 commit into
python:mainfrom
Alishahryar1:ali/faulthandler-code-metadata
Open

Alishahryar1 wants to merge 1 commit into
python:mainfrom
Alishahryar1:ali/faulthandler-code-metadata

Conversation

@Alishahryar1

@Alishahryar1 Alishahryar1 commented Sep 26, 2026 •

Copy link
Copy Markdown

Why

faulthandler.dump_traceback_later() walks other threads without acquiring the GIL so it can diagnose deadlocks. If a target thread releases its current code object during that walk, the watchdog can dereference freed filename, function-name, or line-table metadata and crash instead of producing a diagnostic.

Addresses #158200.

How

Guard code objects and their filename, function-name, line-table, and monitoring metadata before the lock-free traceback path reads them. Preserve readable later fields when one metadata field is invalid, and use ??? only for unavailable fields. Load monitoring pointers with acquire semantics that match their existing release publication, and decode lines from a validated local line-table snapshot.

These checks detect common freed-memory states but do not provide object-lifetime synchronization, so lock-free traversal remains best-effort during concurrent destruction.

@python-cla-bot

python-cla-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@Alishahryar1
Alishahryar1 force-pushed the ali/faulthandler-code-metadata branch from 99ac055 to 2ce7ac6 Compare September 26, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant