You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SR-14802] Concurrency: Unstructured Task Triggering Continuation Can Hang #57150
I create a continuation to allow users to wait for network data captured by an actor and capture its resume in a stored closure. When that capture is complete, I call the enqueued closures to trigger the continuations. Strictly calling the closure within an actor method works fine. Wrapping the closure call in an unstructured task causes a hang and the waiter is never notified. However, simply adding a print statement at the end of the actor method allows it to work. My test iOS project is attached.
This seems to have regressed further in beta 2. Now none of my awaited work seems to complete unless I put a `print` statement in the `request` method before returning the `DataRequest` value. The `print` at the end of `didComplete` is still necessary if the continuations are resumed within an unstructured task.
will await pause
will await go
in pause
in withCheckedContinuation operation
completing withCheckedOperation closure
So it seems that it never actually enters the `go()` function. When it works it seems that the withCheckedContinuationClosure is completed before go is awaited.
This may actually be more related to the issue in release notes "Swift tasks won't have their priority escalated in response to awaiting on their handles. (76127623)" although I don't think there needs to be any escalation. The issue does seem dependent on the different priorities and other test cases seem to now be working. As before with my test cases this doesn't fail every time but does fail a few times in every hundred.
Hmm, this should've been fixed in beta 5. The change that was made was that all priorities get "squashed" to the unspecified level (because the smarter scheduling that took priorities into account wasn't working) so high vs low priority shouldn't matter.
I'll double-check on whether the change landed in time for beta 5 or not.
Activity
typesanitizer commentedon Jun 21, 2021
@swift-ci create
jshier commentedon Jun 26, 2021
This seems to have regressed further in beta 2. Now none of my awaited work seems to complete unless I put a `print` statement in the `request` method before returning the `DataRequest` value. The `print` at the end of `didComplete` is still necessary if the continuations are resumed within an unstructured task.
jshier commentedon Jul 16, 2021
This is still an issue in beta 3. A print statement in the request method is required for any of the work to start.
josephlord commentedon Aug 11, 2021
For information. I'm still seeing failures with this test case in Xcode beta 5 (running on iPhone Simulator):
A failed run prints:
So it seems that it never actually enters the `go()` function. When it works it seems that the withCheckedContinuationClosure is completed before go is awaited.
This may actually be more related to the issue in release notes "Swift tasks won't have their priority escalated in response to awaiting on their handles. (76127623)" although I don't think there needs to be any escalation. The issue does seem dependent on the different priorities and other test cases seem to now be working. As before with my test cases this doesn't fail every time but does fail a few times in every hundred.
typesanitizer commentedon Aug 11, 2021
Hmm, this should've been fixed in beta 5. The change that was made was that all priorities get "squashed" to the unspecified level (because the smarter scheduling that took priorities into account wasn't working) so high vs low priority shouldn't matter.
I'll double-check on whether the change landed in time for beta 5 or not.
typesanitizer commentedon Aug 11, 2021
Looks like not all the patches landed in beta 5, in particular this one: #38709
@josephlord In the meantime, if you do not specify priorities, does the issue go away or are you still seeing the issue without explicit priorities?
josephlord commentedon Aug 11, 2021
Yes. I can’t reproduce without the priorities.
It isn’t blocking anything for me. Just wanted to report results of re-running my exploratory test cases.
fix(polling): use structured TaskGroup so the loop survives Swift 6.2…
fix(polling): bare Task.sleep + pulse counter — no continuation handoffs
fix(polling): unblock the ticker loop that stalls after one sleep cyc…