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 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.

@johng

johng commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Is it possible to add a test that exposes the original issue being fixed?

(I can see this might not be consistently reproducible though, not sure what the precedence is for that for)

@nascheme

Copy link
Copy Markdown
Member Author

Is it possible to add a test that exposes the original issue being fixed?

Yeah, that would be a good idea. I would guess it's possible.

@nascheme

Copy link
Copy Markdown
Member Author

This probably needs a re-write, given GH-159972.

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 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.

2 participants