Apply advisory locks when building source distributions#3525
Merged
charliermarsh merged 2 commits intomainfrom May 13, 2024
Merged
Apply advisory locks when building source distributions#3525charliermarsh merged 2 commits intomainfrom
charliermarsh merged 2 commits intomainfrom
Conversation
charliermarsh
commented
May 11, 2024
| hashes: HashPolicy<'_>, | ||
| client: &ManagedClient<'_>, | ||
| ) -> Result<BuiltWheelMetadata, Error> { | ||
| let _lock = cache_shard.lock().map_err(Error::CacheWrite)?; |
Member
Author
There was a problem hiding this comment.
Realizing... I think I need this to be async? Is that right @ibraheemdev?
Member
There was a problem hiding this comment.
Looks like you hold it across await points, so yeah.
Member
Author
There was a problem hiding this comment.
It’s not a mutex though, it’s a flock. I’d need to do some research.
Member
There was a problem hiding this comment.
Hm.. aren't you still yielding control? So some other task could hit this lock and block without awaiting and returning control to the event loop and consequently to this task? e.g.
- Task A takes lock
- Task A yields to event loop
- Task B attempts to take lock
- Lock is not available so Task B is blocked but has not yielded to the event loop
- Task A is never returned to
- Deadlock
Member
Author
There was a problem hiding this comment.
Wrapped it in a tokio task.
d4444f6 to
f20d3b5
Compare
eda9cb3 to
2227e2b
Compare
f20d3b5 to
1f1e274
Compare
2227e2b to
348aa34
Compare
c940843 to
b61b014
Compare
710119e to
a14de20
Compare
konstin
approved these changes
May 13, 2024
a14de20 to
a7bb014
Compare
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.
Summary
I don't love this, but it turns out that setuptools is not robust to parallel builds: pypa/setuptools#3119. As a result, if you run uv from multiple processes, and they each attempt to build the same source distribution, you can hit failures.
This PR applies an advisory lock to the source distribution directory. We apply it unconditionally, even if we ultimately find something in the cache and don't do a build, which helps ensure that we only build the distribution once (and wait for that build to complete) rather than kicking off builds from each thread.
Closes #3512.
Test Plan
Ran: