-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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-38091: Import deadlock detection causes deadlock #17518
Conversation
The fix here is more of a hack. A proper fix could be something like the below. At least it fixes the reproducer posted by @rlamy . Is there a real-world reproducer you can test it on? diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 8de0e9ee79..7b2bfefdec 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -71,9 +71,20 @@ class _ModuleLock:
lock = _blocking_on.get(tid)
if lock is None:
return False
- tid = lock.owner
- if tid == me:
+ owner_tid = lock.owner
+ if owner_tid == tid:
+ # Lock owner is temporarily blocking on a lock it
+ # already owns. This means it's not actually blocking.
+ # (this can happen at the beginning of acquire() below
+ # -- see bpo 38091)
+ return False
+ if owner_tid == me:
+ # Lock owner is blocking on a lock we own, but we're blocking
+ # on the lock it owns => deadlock.
return True
+ # Move along the chain and find out whether the owner is blocking
+ # on another lock.
+ tid = owner_tid
def acquire(self):
""" |
Maybe a safer way to think about it would be to ask ourselves when has_deadlock() is really supposed to return True. I think it means to return True if the chain
|
I think that this should fix the issue. It caused some intermittent test failures in PyPy, so I guess we should just merge the change there and monitor the CI results. |
@rlamy Did you test this fix on PyPy? |
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.
Marking as rejected until we here back from PyPy that the proposed fix in the PR discussion worked for them.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
I have updated the PR to include the test from https://bugs.python.org/issue38091 , which fails (deadlocks) without the fix and passes with the fix. |
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.
importlib.h
wasn't regenerated and included in this PR. I believe that can be done with make regen-all
(or something like that).
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
Codecov Report
@@ Coverage Diff @@
## master #17518 +/- ##
=========================================
Coverage 82.11% 82.12%
=========================================
Files 1955 1954 -1
Lines 588906 584027 -4879
Branches 44429 44458 +29
=========================================
- Hits 483572 479607 -3965
+ Misses 95679 94777 -902
+ Partials 9655 9643 -12
Continue to review full report at Codecov.
|
Misc/NEWS.d/next/Core and Builtins/2020-02-14-23-10-07.bpo-38091.pwR0K7.rst
Outdated
Show resolved
Hide resolved
@arigo: Status check is done, and it's a failure ❌ . |
@arigo: Status check is done, and it's a success ✅ . |
Thanks @arigo for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
Sorry, @arigo, I could not cleanly backport this to |
Sorry @arigo, I had trouble checking out the |
@arigo any interest in manually backporting this to 3.8 and 3.7? (Chances are it's |
My git-fu is very limited (in general and on github). Do you expect two other pull requests for the 3.7 and 3.8 branches? |
@arigo yep, but don't worry about it too much. I can try to get around to it eventually myself. |
https://bugs.python.org/issue38091
Automerge-Triggered-By: @brettcannon