Skip to content

[Concurrency] Parent task cancellation must cancel task group itself. #80794

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

Merged
merged 3 commits into from
Apr 14, 2025

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Apr 14, 2025

Seems that during refactorings of child cancellations we somehow missed
also cancelling the group itself. It seems we did not have good test
coverage of the addTaskUnlessCancelled somehow and thus this slipped
through.

This adds a regression test for addTaskUnlessCancelled and fixes how we
handle the cancellation effect in TaskStatus.

resolves #80789
resolves rdar://149177600

Seems that during refactorings of child cancellations we somehow missed
also cancelling the group itself. It seems we did not have good test
coverage of the addTaskUnlessCancelled somehow and thus this slipped
through.

This adds a regression test for addTaskUnlessCancelled and fixes how we
handle the cancellation effect in TaskStatus.

resolves swiftlang#80789
resolves rdar://149177600
@ktoso ktoso requested a review from mikeash April 14, 2025 08:13
@ktoso
Copy link
Contributor Author

ktoso commented Apr 14, 2025

Refactored the _swift_taskGroup_cancelAllChildren_unlocked to be _swift_taskGroup_cancel_unlocked etc, so these do the right thing, rather just part of the right thing. FYI @mikeash

This way we do the right thing always when cancelling the group;
and we MAY visit the child tasks if we have to.
@ktoso ktoso force-pushed the wip-parent-cancel-must-cancel-group branch from b3c3a2c to 94423da Compare April 14, 2025 08:30
@ktoso
Copy link
Contributor Author

ktoso commented Apr 14, 2025

@swift-ci please smoke test

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks good to me. I'd prefer it if we used something other than than Task.sleep() in tests where possible though, since relying on sleep timings makes for flaky tests.

@ktoso
Copy link
Contributor Author

ktoso commented Apr 14, 2025

@swift-ci please smoke test

@ktoso ktoso force-pushed the wip-parent-cancel-must-cancel-group branch from 7d662fa to a9bcf39 Compare April 14, 2025 10:26
@ktoso
Copy link
Contributor Author

ktoso commented Apr 14, 2025

@swift-ci please smoke test

@ktoso ktoso enabled auto-merge April 14, 2025 15:41
@ktoso ktoso merged commit aaec5aa into swiftlang:main Apr 14, 2025
3 checks passed
@ktoso ktoso deleted the wip-parent-cancel-must-cancel-group branch April 15, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

with[Throwing]DiscardingTaskGroup + Task.cancel() + addTaskUnlessCancelled
2 participants