-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
onCancel callback of the withTaskCancellationHandler() is called more than once. #80161
Comments
cc @ktoso – is this possibility expected? |
Sorry to hijack this issue, but the following pattern also crashes without a precondition check.
|
A cancellation handler should run only ever once, so there may be something off here. We'll have to investigate. Please always include detailed environment you're testing on (macos? ios? linux? which version of swift) when reporting bugs. I did reproduce the initial reproducer on a mac, we should look into this some more. |
It's a race between the task_cancel and the "immediately run the handler". I think we can have a fix soon. |
…ith a check to is cancelled - swiftlang#80161
This avoids the potential to race with the triggering coming from task_cancel, because we first set the cancelled flag, and only THEN take the lock and iterate over the inserted records. Because of this we could: T1 flip the cancelled bit; T2 observes that, and triggers "immediately" during installing the handler record. T1 then proceeds to lock records and trigger it again, causing a double trigger of the cancellation handler. resolves swiftlang#80161 resolves rdar://147493150
Fix incoming #80456 |
…k. (#80456) This avoids the potential to race with the triggering coming from task_cancel, because we first set the cancelled flag, and only THEN take the lock and iterate over the inserted records. Because of this we could: T1 flip the cancelled bit; T2 observes that, and triggers "immediately" during installing the handler record. T1 then proceeds to lock records and trigger it again, causing a double trigger of the cancellation handler. resolves #80161 resolves rdar://147493150
Thanks! |
Description
The documentation doesn't clearly state that the
onCancel
can be called more than once.We observed sometimes it happens and not clear is it bug or not.
Minimized reproducing test is available on github
Reproduction
Sometimes test fails:
Expected behavior
precondition
check at line 39 always successEnvironment
Additional information
No response
The text was updated successfully, but these errors were encountered: