[clang][modules] Prevent deadlock in module cache (#182722)#12833
Merged
jansvoboda11 merged 1 commit intostable/21.xfrom Apr 27, 2026
Merged
[clang][modules] Prevent deadlock in module cache (#182722)#12833jansvoboda11 merged 1 commit intostable/21.xfrom
jansvoboda11 merged 1 commit intostable/21.xfrom
Conversation
When there's a dependency cycle between modules, the dependency scanner may encounter a deadlock. This was caused by not respecting the lock timeout. But even with the timeout implemented, leaving `unsafeMaybeUnlock()` unimplemented means trying to take a lock after a timeout would still fail and prevent making progress. This PR implements this API in a way to avoid UB on `std::mutex` (when it's unlocked by someone else than the owner). Lastly, this PR makes sure that `unsafeUnlock()` ends the wait of existing threads, so that they don't need to hit the full timeout amount. This PR also implements `-fimplicit-modules-lock-timeout=<seconds>` that allows tweaking the default 90-second lock timeout, and adds `#pragma clang __debug sleep` that makes it easier to achieve desired execution ordering. rdar://170738600 (cherry picked from commit de4a1a7)
Author
|
@swift-ci please test |
Author
|
@swift-ci please test |
Author
|
swiftlang/swift#88652 |
akyrtzi
approved these changes
Apr 27, 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.
When there's a dependency cycle between modules, the dependency scanner may encounter a deadlock. This was caused by not respecting the lock timeout. But even with the timeout implemented, leaving
unsafeMaybeUnlock()unimplemented means trying to take a lock after a timeout would still fail and prevent making progress. This PR implements this API in a way to avoid UB onstd::mutex(when it's unlocked by someone else than the owner). Lastly, this PR makes sure thatunsafeUnlock()ends the wait of existing threads, so that they don't need to hit the full timeout amount.This PR also implements
-fimplicit-modules-lock-timeout=<seconds>that allows tweaking the default 90-second lock timeout, and adds#pragma clang __debug sleepthat makes it easier to achieve desired execution ordering.rdar://170738600
(cherry picked from commit de4a1a7)