-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
raise BrokenResourceError if lock owner has exited. #3080
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3080 +/- ##
=======================================
Coverage 99.60% 99.60%
=======================================
Files 121 121
Lines 17882 17900 +18
Branches 3214 3221 +7
=======================================
+ Hits 17811 17829 +18
Misses 50 50
Partials 21 21
|
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.
Can you add a newsfragment?
See https://github.com/python-trio/trio/issues/3035 | ||
""" | ||
lock = trio.Lock() | ||
with pytest.raises(trio.TooSlowError): |
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.
How about xfailing this test?
and inspect.getcoroutinestate(self._owner.coro) is inspect.CORO_CLOSED | ||
): | ||
raise trio.BrokenResourceError( | ||
"Attempted acquire on Lock which will never be released, owner has exited.", |
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.
"Attempted acquire on Lock which will never be released, owner has exited.", | |
"Attempted acquire on Lock which will never be released as the owner has exited.", |
I'm not sure this is the ideal message either way but the alternative I can think of isn't great either: "Deadlock detected: acquiring lock which will never be released."
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.
I'm somewhat concerned about the performance impact of inspect.getcoroutinestate
in acquire_nowait()
, which might be fine.
The larger problem is that it only addresses the case where the holding task is already gone at acquire-time; I think we should probably go directly to the general solution of adding a ParkingLot.mark_resource_broken()
method and using that from Lock.
Good point, if someone's polling
Yeah, the problem is we can't just add a way to poison a |
I ran a simple benchmark now and could not detect any difference with or without a call to
Yes this PR intentionally only made the easy fix from #3035 (comment), but if the full fix turns out doable then we'll close this one. |
This will probably end up closed in favor of #3081 |
Now unnecessary. |
Partially addresses #3035
test_lock_multiple_acquire
is very meaningfulIt's possible that a full implementation for #3035 makes this redundant, but this was easy enough to write&test I thought I might as well push it as a PR that improves the status quo for now.