Detect unclosed cancel scopes when a task exits - #3510
Open
Sakshamm-Goyal wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3510 +/- ##
===============================================
Coverage 100.00000% 100.00000%
===============================================
Files 128 128
Lines 19454 19515 +61
Branches 1321 1327 +6
===============================================
+ Hits 19454 19515 +61
🚀 New features to boost your workflow:
|
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.
Summary
Fixes #3329.
A task can enter a
CancelScope, return without exiting it, and leave another task able to exit that scope. The existing task-exit checks catch abandoned scope trees and unclosed child nurseries, but not this still-attached scope.Detect a task exiting with a cancellation status different from its parent nursery's status. Report a scope-stack corruption error, preserving the original exception as context when present, and clean up the unclosed scopes and their registered deadlines. Existing child-nursery recovery is unchanged.
Regression coverage includes nested scopes, cancellation,
nursery.start()adoption, guest mode, original exception context and enclosing parent-scope preservation. A release note is included.Validation
a3d7cddeacef74c87f667e9f9e8615f2ab7ce894because no corruption error is raised.src/triopass for Darwin, Linux and Windows targets.__notes__failure also reproduced on unchanged upstream; Python 3.10's corresponding checks pass. No claim of full platform CI coverage.Related work
This covers a remaining case after #3307: the exiting task has an unclosed scope but no unclosed child nursery. It does not change the cancelled-task adoption policy discussed in #2896.
AI assistance
This change and its tests were developed and validated with OpenAI Codex assistance.