Swift Structured Concurrency: Task cancellation propagation across actor boundaries
0 reputation · 15 May 2021, 07:53 UTC
Cancellation Behavior in Distributed Actor Isolation
Swift's cooperative cancellation model ensures that cancellation propagates from parent tasks to child tasks created via async let or TaskGroup. This mechanism relies on the task hierarchy to signal termination to all nested operations.
When asynchronous operations transition across different actor isolation boundaries, the timing and priority of this propagation can vary. There is uncertainty regarding how the system handles the latency between a parent task being marked as cancelled and the child task on a separate actor receiving that signal, especially when the actor's mailbox is heavily congested.
Given a high-load environment using Swift 5.10+, what is the guaranteed behavior for cancellation propagation across actor boundaries? Does the system prioritize the cancellation signal over pending messages in the actor's queue?