Stop resuming continuations while holding the pending lookup mutex in RegistryDownloadsManager/RepositoryManager - #10477
Open
plemarquand wants to merge 1 commit into
Conversation
`RegistryDownloadsManager.lookup` and `RepositoryManager.lookup` both wrapped a `Mutex.withLock` in `withCheckedContinuation` and then resumed the continuation inside the lock. This is a common way to end up with deadlocked code. The code that runs after the continuation is resumed but before the lock is released can end up trying to acquire the same lock again, which will deadlock. The section inside `withCheckedContinuation` was already synchronous, so the continuation wasn't even required. We can just return the value directly from `withLock` directly.
plemarquand
requested review from
bkhouri,
bripeticca,
cmcgee1024,
daveinglis,
daveyc123,
dschaefer2,
jakepetroules,
owenv and
rconnell9
as code owners
September 1, 2026 13:26
Contributor
Author
|
cc @FranzBusch |
Contributor
Author
|
@swift-ci test |
FranzBusch
reviewed
Sep 1, 2026
| return inFlight | ||
| } | ||
|
|
||
| let lookupTask = Task { |
Member
There was a problem hiding this comment.
I would normally recommend even moving this outside the lock. This is also an outcall to enqueue the task on the executor. While it doesn't cause a problem here it could potentially. I know it's a bit awkward since you gotta introduce another state which is about to start. I leave it to you if you wanna do that change or file an issue for it.
FranzBusch
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RegistryDownloadsManager.lookupandRepositoryManager.lookupboth wrapped aMutex.withLockinwithCheckedContinuationand then resumed the continuation inside the lock.This is a common way to end up with deadlocked code. The code that runs after the continuation is resumed but before the lock is released can end up trying to acquire the same lock again, which will deadlock.
The section inside
withCheckedContinuationwas already synchronous, so the continuation wasn't even required. We can just return the value directly fromwithLockdirectly.