Skip to content

gh-155400: Fix deadlock with type_lock_prevent_release() - #155401

Draft
nascheme wants to merge 1 commit into
python:mainfrom
nascheme:gh-155400-type-lock-prevent-release-deadlock
Draft

gh-155400: Fix deadlock with type_lock_prevent_release()#155401
nascheme wants to merge 1 commit into
python:mainfrom
nascheme:gh-155400-type-lock-prevent-release-deadlock

Conversation

@nascheme

@nascheme nascheme commented Aug 8, 2026

Copy link
Copy Markdown
Member

Two threads assigning to a special method of the same class could deadlock in the free-threaded build. If type_lock_prevent_release() only acts on TYPE_LOCK then we can get lock inversion. This happens when BEGIN_TYPE_DICT_LOCK() is used and the critical section holds both mutexes. We need to prevent release of both mutexes.

Two threads assigning to a special method of the same class could
deadlock in the free-threaded build.  If type_lock_prevent_release()
only acts on TYPE_LOCK then we can get lock inversion.  This happens
when BEGIN_TYPE_DICT_LOCK() is used and the critical section holds
both mutexes.  We need to prevent release of both mutexes.

Assisted-by: Claude
@nascheme

nascheme commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

This PR requires GH-155370 to be merged first otherwise the unit test added exposes data-races.

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