-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
Attempt to recover from cancel scope nesting violations #1061
Conversation
When exiting an outer cancel scope before some inner cancel scope nested inside it, Trio would previously raise a confusing chain of internal errors. One common source of this misbehavior was an async generator that yielded within a cancel scope. Now the mis-nesting condition will be noticed and in many cases the user will receive a single RuntimeError with a useful traceback. This is a best-effort feature, and it's still possible to fool Trio if you try hard enough, such as by closing a nursery's cancel scope from within some child task of the nursery. Fixes python-trio#882. Relevant to python-trio#1056, python-trio#264.
Codecov Report
@@ Coverage Diff @@
## master #1061 +/- ##
==========================================
+ Coverage 99.15% 99.16% +<.01%
==========================================
Files 102 102
Lines 12374 12465 +91
Branches 923 936 +13
==========================================
+ Hits 12270 12361 +91
Misses 83 83
Partials 21 21
|
For the lazy, would you post an example traceback with and without this change? |
With this change:
Without this change:
|
# of a cancel status that's been closed. This is used to permit | ||
# recovery from mis-nested cancel scopes (well, at least enough | ||
# recovery to show a useful traceback). | ||
abandoned_by_misnesting = attr.ib(default=False, init=False, repr=False) |
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.
Is this a new public API?
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.
CancelStatus isn't part of the public API, so abandoned_by_misnesting and encloses() aren't either. They are non-underscore-prefixed because they're safe to use by other code in _run without worrying about CancelStatus's invariants.
Codecov report is nonsensical on this one too. |
Looks good – let's see if it helps :-) |
When exiting an outer cancel scope before some inner cancel scope nested inside it, Trio would previously raise a confusing chain of internal errors. One common source of this misbehavior was an async generator that yielded within a cancel scope. Now the mis-nesting condition will be noticed and in many cases the user will receive a single RuntimeError with a useful traceback. This is a best-effort feature, and it's still possible to fool Trio if you try hard enough, such as by closing a nursery's cancel scope from within some child task of the nursery.
Fixes #882. Relevant to #1056, #264.