FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-155400: Fix deadlock with type_lock_prevent_release() by nascheme · Pull Request #155401 · python/cpython · GitHub

Repository navigation

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

Merged
kumaraditya303 merged 2 commits into
python:mainfrom
nascheme:gh-155400-type-lock-prevent-release-deadlock
Aug 15, 2026
Merged

kumaraditya303 merged 2 commits into
python:mainfrom
nascheme:gh-155400-type-lock-prevent-release-deadlock

Conversation

nascheme commented Aug 8, 2026 •
edited by bedevere-app Bot
Loading

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

Copy link
Copy Markdown
Member Author

Setting as release blocker. When discussing this with @kumaraditya303, he suspects that some libraries could trigger this deadlock when they create types.

nascheme marked this pull request as ready for review August 12, 2026 15:19
nascheme requested a review from markshannon as a code owner August 12, 2026 15:19
kumaraditya303 merged commit 50fcb91 into python:main Aug 15, 2026
58 checks passed
kumaraditya303 added the needs backport to 3.15 bugs and security fixes label Aug 15, 2026

Copy link
Copy Markdown

Thanks @nascheme for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

bedevere-app Bot commented Aug 15, 2026

Copy link
Copy Markdown

GH-155822 is a backport of this pull request to the 3.15 branch.

bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Aug 15, 2026

Copy link
Copy Markdown
Member Author

Note that a unit test added by this PR exposes an existing leak, see gh-155978. This leak causes some refleak build bots to fail.

hugovk pushed a commit that referenced this pull request Aug 19, 2026
…55401) (#155822)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL