Skip to content

Fix task leaks in TaskScheduler shutdown#2677

Open
rintaro wants to merge 1 commit into
swiftlang:mainfrom
rintaro:taskscheduler-shutdown-fixes
Open

Fix task leaks in TaskScheduler shutdown#2677
rintaro wants to merge 1 commit into
swiftlang:mainfrom
rintaro:taskscheduler-shutdown-fixes

Conversation

@rintaro
Copy link
Copy Markdown
Member

@rintaro rintaro commented May 29, 2026

shutDown only canceled currentlyExecutingTasks, leaving pendingTasks untouched. QueuedTask were leaked via the self retain cycles in with the resultTask closure, and the task never completes itself.

And possibly external callers awaiting waitToFinish() on a pending task hang forever.

Cancel pending tasks too: task.cancel() cancels resultTask, the for await over the stream exits immediately on cancellation, and waitToFinish() returns immediately.

(In reality, I don't believe this affects anything because we only shutdown SourceKitLSPServer when process exits)

`shutDown` only cancels `currentlyExecutingTasks`, leaving
`pendingTasks` untouched. External callers awaiting `waitToFinish()`
on a pending task hang forever — `resultTask` keeps awaiting an
`AsyncStream` that the scheduler will never yield into once
`isShutDown` is set — and each such `QueuedTask` is leaked via the
strong cycle through its `resultTask` closure.

Cancel pending tasks too: `task.cancel()` cancels `resultTask`, the
`for await` over the stream exits immediately on cancellation, and
`waitToFinish()` returns in microseconds.
@rintaro
Copy link
Copy Markdown
Member Author

rintaro commented May 29, 2026

@swift-ci Please test

@rintaro
Copy link
Copy Markdown
Member Author

rintaro commented May 29, 2026

@swift-ci Please test Windows

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.

2 participants