-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DiscardingTG] Undo pointer auth workaround; fix memory leaks #65613
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
[DiscardingTG] Undo pointer auth workaround; fix memory leaks #65613
Conversation
test/Concurrency/Runtime/async_taskgroup_discarding_noLeaks.swift
Outdated
Show resolved
Hide resolved
test/Concurrency/Runtime/async_taskgroup_discarding_noLeaks.swift
Outdated
Show resolved
Hide resolved
8f660b4
to
72f14b5
Compare
@swift-ci please smoke test |
priority: TaskPriority? = nil, | ||
operation: __owned @Sendable @escaping () async -> DiscardedResult |
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.
This entire change to () -> T
was a hotfix to temporarily unbreak but it is very wrong, we must get back to -> Void
✅ This fixes the (b) leaks the by undoing what introduced them in the first place.
This is primarily stuck on pointer auth issues |
8ba48c6
to
679a24a
Compare
@swift-ci please smoke test |
[lit] cleanup lit leaks target
679a24a
to
ae58811
Compare
ae58811
to
9f5a707
Compare
resumeWaitingTask(readyErrorItem.getTask(), assumed, | ||
/*hadErrorResult=*/true, | ||
alreadyDecrementedStatus, | ||
/*taskWasRetained=*/true); |
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.
hunting this one down took way too long... this is another case where we dequeue the retained error task and need to release it later
cdd127b
to
d82de55
Compare
@swift-ci please smoke test |
ce1c880
to
0b088e2
Compare
0b088e2
to
760cb44
Compare
@@ -1369,6 +1383,11 @@ void TaskGroupBase::resumeWaitingTask( | |||
// locks) because we know that the child task is completed and | |||
// we can't be holding its locks ourselves. | |||
_swift_taskGroup_detachChild(asAbstract(this), completedTask); | |||
if (isDiscardingResults() && hadErrorResult && taskWasRetained) { |
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.
✅ This fixes the (a) leaks because we need to balance the extra retain we do when we store the task for future use like this.
In other words, in this case of the discarding group we were missing this balancing release:
// Retain the task while it is in the queue; it must remain alive until
// it is found by poll. This retain will be balanced by the release in waitAll.
assert(hadErrorResult); // a discarding group may only store an errored task.
swift_retain(completedTask);
@swift-ci please smoke test |
std::tie(taskEntry, initialContextSize) = | ||
TaskCreateFlags taskCreateFlags(rawTaskCreateFlags); | ||
|
||
if (taskCreateFlags.isDiscardingTask()) { |
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.
the pointer auth dance for the nullary function type:
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.
Okay. I think this seems reasonable.
Thanks for review John! A bit confused why same commits worked on Windows 5.9 but not here, in a lit configuration failure. Let's try again |
@swift-ci please smoke test Windows |
Silly main + windows only issue in lit config:
Fixed I hope; @swift-ci please smoke test and merge |
68a5e09
to
e3d4b55
Compare
@swift-ci please smoke test and merge |
Pending on the CI unbreak: #66138 |
@swift-ci please smoke test and merge |
… Void closure Since swiftlang#65613, DiscardingTG started to accept `() -> Void` instead of `() -> T`, but it also changed the number of arguments accepted by the closure from 3 to 2. So it should use `non_future_adapter` instead of `future_adapter` to avoid runtime signature mismatch.
… Void closure Since swiftlang#65613, DiscardingTG started to accept `() -> Void` instead of `() -> T`, but it also changed the number of arguments accepted by the closure from 3 to 2. So it should use `non_future_adapter` instead of `future_adapter` to avoid runtime signature mismatch.
… Void closure Since swiftlang#65613, DiscardingTG started to accept `() -> Void` instead of `() -> T`, but it also changed the number of arguments accepted by the closure from 3 to 2. So it should use `non_future_adapter` instead of `future_adapter` to avoid runtime signature mismatch.
There are two leaks in the group.
"first error task leaks"
(a) the "the first error task that we RETAIN" and later on use to automatically re-throw the "first thrown by a child task error" task was not released;
"all values leak"
(b) due to the "hot fix" for pointer auth #65220 done for rdar://107574868 where we changed the signature of addTask from
()->()
(what it must be), to()->T
in order to work around pointer-auth issues we introduced a leak and ALL "discarded" values would be leaking since we would not release that T value. The correct way to solve this is to undo this workaround and use correct pointer auth, which this PR does.We must fix the method signature and undo the hack which #65223 was.
Resolves: rdar://108829466