-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard against concurrent cache writes on Windows (#11007)
## Summary On Windows, we have a lot of issues with atomic replacement and such. There are a bunch of different failure modes, but they generally involve: trying to persist a fail to a path at which the file already exists, trying to replace or remove a file while someone else is reading it, etc. This PR adds locks to all of the relevant database paths. We already use these advisory locks when building source distributions; now we use them when unzipping wheels, storing metadata, etc. Closes #11002. ## Test Plan I ran the following script: ```shell # Define the cache directory path $cacheDir = "C:\Users\crmar\workspace\uv\cache" # Clear the cache directory if it exists if (Test-Path $cacheDir) { Remove-Item -Recurse -Force $cacheDir } # Create the cache directory again New-Item -ItemType Directory -Force -Path $cacheDir # Define the command to run with --cache-dir flag $command = { param ($venvPath) # Create a virtual environment in the specified path with --python uv venv $venvPath # Run the pip install command with --cache-dir flag C:\Users\crmar\workspace\uv\target\profiling\uv.exe pip install flask==1.0.4 --no-binary flask --cache-dir C:\Users\crmar\workspace\uv\cache -v --python $venvPath } # Define the paths for the different virtual environments $venv1 = "C:\Users\crmar\workspace\uv\venv1" $venv2 = "C:\Users\crmar\workspace\uv\venv2" $venv3 = "C:\Users\crmar\workspace\uv\venv3" $venv4 = "C:\Users\crmar\workspace\uv\venv4" $venv5 = "C:\Users\crmar\workspace\uv\venv5" # Start the command in parallel five times using Start-Job, each with a different venv $job1 = Start-Job -ScriptBlock $command -ArgumentList $venv1 $job2 = Start-Job -ScriptBlock $command -ArgumentList $venv2 $job3 = Start-Job -ScriptBlock $command -ArgumentList $venv3 $job4 = Start-Job -ScriptBlock $command -ArgumentList $venv4 $job5 = Start-Job -ScriptBlock $command -ArgumentList $venv5 # Wait for all jobs to complete $jobs = @($job1, $job2, $job3, $job4, $job5) $jobs | ForEach-Object { Wait-Job $_ } # Retrieve the results (optional) $jobs | ForEach-Object { Receive-Job -Job $_ } # Clean up the jobs $jobs | ForEach-Object { Remove-Job -Job $_ } ``` And ensured it succeeded in five straight invocations (whereas on `main`, it consistently fails with a variety of different traces).
- Loading branch information
1 parent
321f8cc
commit f1840c7
Showing
7 changed files
with
137 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.