Skip to content

🍒[5.9.0][TaskGroup] Fix unlock order, add missing detaches and add more assertions #67892

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 2 commits into from
Aug 11, 2023

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Aug 11, 2023

Cherry pick of https://github.com/apple/swift/pull/67819/commits to release/5.9.0


Description: A task group resumes the "waiting task" in numerous situations. Currently tasks were scheduled and then the group was unlocked -- this can lead to races between the scheduled task and the group unlock and unpredictable behavior. Instead, we must unlock the group and THEN schedule the waiting task on order to avoid potential use-after free of the lock (as the unlock() happens).
Risk: Medium, the change reorganizes code in order to allow us to unlock and THEN schedule the task. This forced some general refactoring in order to be able to get this pattern.
Reward Medium, resolves very rare crashes which could occur when just the right scheduling timing would happen. These issues are very rare, and have remained undetected until recently.
Review by: @mikeash @DougGregor
Testing: CI testing, enabled all task group tests for the first time in a long time and all passing consistently on all platforms.
Original PR: #67590
Radar: rdar://113331923 (test reenable rdar://113016918)
Related Radar: The following was the same issue however in a more crucial code path: rdar://113032582

ktoso added 2 commits August 11, 2023 16:58
reenable async_taskgroup_discarding_dontLeak.swift

[DiscardingTaskGroup] Properly detach when LAST task is failed, and prior failure was already stored

[TaskGroup] Must detach discarded task, THEN unlock before resume waiting

revamping locking scheme, test this a bunch

stabilize println based test a bit more against timing

re-enable tsan test: async_taskgroup_next

reenable async_taskgroup_next_on_pending

disable debugging tricks

unlock test: async_taskgroup_asynciterator_semantics

make use of unreachable

cleanups

cleanup for freestanding mode
@ktoso ktoso requested a review from a team as a code owner August 11, 2023 07:58
@ktoso
Copy link
Contributor Author

ktoso commented Aug 11, 2023

@swift-ci please test

@ktoso ktoso added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 concurrency runtime Feature: umbrella label for concurrency runtime features labels Aug 11, 2023
@hborla hborla merged commit 0b85f99 into swiftlang:release/5.9.0 Aug 11, 2023
@ktoso ktoso deleted the pick-task-group-unlock-5.9.0 branch August 12, 2023 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency runtime Feature: umbrella label for concurrency runtime features 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants