-
Notifications
You must be signed in to change notification settings - Fork 10.5k
🍒[5.9][TaskGroup] Fix unlock order, add missing detaches and add more assertions #67819
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
🍒[5.9][TaskGroup] Fix unlock order, add missing detaches and add more assertions #67819
Conversation
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
1ab7b64
to
2e6381f
Compare
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
auto waitingContext = | ||
static_cast<TaskFutureWaitAsyncContext *>( | ||
waitingTask->ResumeContext); | ||
// Run the task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this comment isn't entirely accurate :-) (same as on the review of the original PR).
Added the docs-only code review change 1195955 from the original PR review. Might as well give this another full test run as well 👍 |
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…before-run 🍒[5.9][TaskGroup] Fix unlock order, add missing detaches and add more assertions
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