Use a flock to avoid concurrent initialization of project environments#11259
Use a flock to avoid concurrent initialization of project environments#11259charliermarsh merged 1 commit intomainfrom
Conversation
| /// Grab a file lock for the environment to prevent concurrent writes across processes. | ||
| pub(crate) async fn lock(workspace: &Workspace) -> Result<LockedFile, std::io::Error> { | ||
| LockedFile::acquire( | ||
| std::env::temp_dir().join(format!( |
There was a problem hiding this comment.
Isn't this naughty? Aren't you supposed to grab some uv-specific tmp dir location?
(I thought we removed these intentionally in the past, the only remaining reference is in the trampolines)
There was a problem hiding this comment.
Oh and
uv/crates/uv-python/src/environment.rs
Line 311 in d281f49
There was a problem hiding this comment.
Yeah, we do this elsewhere. I guess we could create a directory within env::temp_dir called uv?
There was a problem hiding this comment.
Honestly I kind of think we should do this everywhere rather than creating .lock files in virtualenvs, etc.
There was a problem hiding this comment.
I thought there was a very intentional reason we used co-located temporary files or the cache instead of /tmp
There was a problem hiding this comment.
I don't know if it's relevant here but OS tempdirs are popular sources of Different Filesystem, and moving a file across filesystems does not benefit from the same atomicity guarantees (it's like cp instead of mv).
There was a problem hiding this comment.
(This is broadly possible with basically any random Other Directory, hence "do atomic moves/renames only in the ~same directory" is often advisable)
There was a problem hiding this comment.
Yeah I think this is where we landed in Discord — co-location is critical for any atomic rename operations.
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.5.27` -> `0.5.29` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>astral-sh/uv (astral-sh/uv)</summary> ### [`v0.5.29`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0529) [Compare Source](astral-sh/uv@0.5.28...0.5.29) ##### Enhancements - Add `--bare` option to `uv init` ([#​11192](astral-sh/uv#11192)) - Add support for respecting `VIRTUAL_ENV` in project commands via `--active` ([#​11189](astral-sh/uv#11189)) - Allow the project `VIRTUAL_ENV` warning to be silenced with `--no-active` ([#​11251](astral-sh/uv#11251)) ##### Python The managed Python distributions have been updated, including: - CPython 3.12.9 - CPython 3.13.2 - pkg-config files are now relocatable See the [`python-build-standalone` release notes](https://github.com/astral-sh/python-build-standalone/releases/tag/20250205) for more details. ##### Bug fixes - Always use base Python discovery logic for cached environments ([#​11254](astral-sh/uv#11254)) - Use a flock to avoid concurrent initialization of project environments ([#​11259](astral-sh/uv#11259)) - Fix handling of `--all-groups` and `--no-default-groups` flags ([#​11224](astral-sh/uv#11224)) ##### Documentation - Minor touchups to the Docker provenance docs ([#​11252](astral-sh/uv#11252)) - Move content from the `mkdocs.public.yml` into the template ([#​11246](astral-sh/uv#11246)) ### [`v0.5.28`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0528) [Compare Source](astral-sh/uv@0.5.27...0.5.28) ##### Bug fixes - Allow discovering virtual environments from the first interpreter found on the `PATH` ([#​11218](astral-sh/uv#11218)) - Clear ephemeral overlays when running tools ([#​11141](astral-sh/uv#11141)) - Disable SSL in Git commands for `--allow-insecure-host` ([#​11210](astral-sh/uv#11210)) - Fix hardlinks in tar unpacking ([#​11221](astral-sh/uv#11221)) - Set base executable when returning virtual environment ([#​11209](astral-sh/uv#11209)) - Use base Python for cached environments ([#​11208](astral-sh/uv#11208)) ##### Documentation - Add documentation on verifying Docker image attestations ([#​11140](astral-sh/uv#11140)) - Add `last updated` to documentation ([#​11164](astral-sh/uv#11164)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNTguMSIsInVwZGF0ZWRJblZlciI6IjM5LjE1OC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Summary
If you
uv runfrom the same directory via multiple processes at the same time, some of them will fail as they'll see an "incomplete" virtual environment.Closes #11219.