Skip to content

gh-158194: Pin the type lock in PyType_Freeze() - #158674

Open
nascheme wants to merge 1 commit into
python:mainfrom
nascheme:gh-158194-type-freeze-pin
Open

nascheme wants to merge 1 commit into
python:mainfrom
nascheme:gh-158194-type-freeze-pin

Conversation

@nascheme

@nascheme nascheme commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Fix PyType_Freeze releasing the type lock while waiting for a stop-the-world pause in the free-threaded build. Another thread could modify the type before the frozen type's caches were invalidated, and the release could deadlock against a thread waiting for the pause with the type lock held.

PyType_Freeze() stopped the world under the type lock without pinning
it, so the lock could be released while waiting for the pause.  Pin it
with type_lock_prevent_release() like the other type-lock callers of
types_stop_world().
@nascheme
nascheme requested a review from markshannon as a code owner October 3, 2026 18:55
@nascheme nascheme added type-bug An unexpected behavior, bug, or error topic-free-threading needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Oct 3, 2026
@nascheme

nascheme commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

This fix in this PR is the same code change as suggested by @scasella, without the additional code comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes topic-free-threading type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant