-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-39776: Lock ++interp->tstate_next_unique_id. (GH-18746) #18746
Conversation
- Threads created by PyGILState_Ensure() could have a duplicate tstate->id.
Oh. That's an interesting bug :-) Would you mind to add a NEWS entry? The fix should be backported to 3.7 and 3.8 branches. It's a severe bug, likely very hard to reproduce :-( |
Codecov Report
@@ Coverage Diff @@
## master #18746 +/- ##
=======================================
Coverage 82.13% 82.14%
=======================================
Files 1956 1956
Lines 590161 590206 +45
Branches 44493 44503 +10
=======================================
+ Hits 484758 484798 +40
Misses 95751 95751
- Partials 9652 9657 +5
Continue to review full report at Codecov.
|
if (init) { | ||
_PyThreadState_Init(tstate); | ||
} | ||
|
||
HEAD_LOCK(runtime); | ||
tstate->id = ++interp->tstate_next_unique_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, is the reason for the problem that the increment was done unlocked?
@vstinner Yes, it deserves a blurb. :) @pitrou Yes, I printed Line 201 in 89aa469
sometimes returned cached values that had already been deallocated by a previous thread With this fix there are no longer any duplicates and the test does not crash. If you review,
|
Yes, |
if (init) { | ||
_PyThreadState_Init(tstate); | ||
} | ||
|
||
HEAD_LOCK(runtime); | ||
tstate->id = ++interp->tstate_next_unique_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The location is unfortunate, but _PyThreadState_Init(tstate)
does not use this field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from me.
@skrah: Please replace |
Thanks @skrah for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
Sorry @skrah, I had trouble checking out the |
Sorry, @skrah, I could not cleanly backport this to |
Thanks! Backports will follow ... |
GH-18752 is a backport of this pull request to the 3.8 branch. |
GH-18753 is a backport of this pull request to the 3.7 branch. |
https://bugs.python.org/issue39776