Skip to content

gh-151593: Fix dead lock in PyDict insert_split_key()#152200

Open
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:dict_deadlock
Open

gh-151593: Fix dead lock in PyDict insert_split_key()#152200
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:dict_deadlock

Conversation

@vstinner

@vstinner vstinner commented Jun 25, 2026

Copy link
Copy Markdown
Member

Do not hold LOCK_KEYS() lock when calling PyType_Modified() to avoid a deadlock.

Do not hold LOCK_KEYS() lock when calling PyType_Modified() to avoid
a deadlock.

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
@vstinner

Copy link
Copy Markdown
Member Author

On Python built with ./configure --with-pydebug --with-system-expat --with-thread-sanitizer --disable-gil, I can easily reproduce the issue with:

./python -m test test_abc --parallel-threads=10 -v -F

It only takes 1 or 2 iterations to trigger the deadlock.

With this change, I can no longer reproduce the deadlock: the test is running for 5 minutes (test_abc passed 35 times in a row).

@vstinner

Copy link
Copy Markdown
Member Author

@dpdani @colesbury @nascheme: Would you mind to review this fix?

I just converted @nascheme's comment into an actual PR.

@dpdani dpdani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment, but otherwise LGTM 👍

Comment thread Objects/dictobject.c
@vstinner

Copy link
Copy Markdown
Member Author

@dpdani: I added a comment on LOCK_KEYS() based on previous comments on pull requests and issues. Does it look good to you?

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this

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.

3 participants