Attempt to recover from cancel scope nesting violations#1061
Merged
njsmith merged 5 commits intopython-trio:masterfrom Jun 4, 2019
Merged
Attempt to recover from cancel scope nesting violations#1061njsmith merged 5 commits intopython-trio:masterfrom
njsmith merged 5 commits intopython-trio:masterfrom
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
|
Member
|
For the lazy, would you post an example traceback with and without this change? |
Member
Author
With this change: Without this change: |
njsmith
reviewed
Jun 2, 2019
| # 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) |
Member
Author
There was a problem hiding this comment.
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.
Member
Author
|
Codecov report is nonsensical on this one too. |
Member
|
Looks good – let's see if it helps :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.