Don't fail on creation of sdist-vX/.git if it already exists#17825
Don't fail on creation of sdist-vX/.git if it already exists#17825
sdist-vX/.git if it already exists#17825Conversation
crates/uv-cache/src/lib.rs
Outdated
| fs_err::OpenOptions::new() | ||
| .create(true) | ||
| .write(true) | ||
| .open(phony_git)?; |
There was a problem hiding this comment.
Does this return a different error type with create(true) such that we can tell if it exists already without an extra syscall?
There was a problem hiding this comment.
(per create(true) I don't think the title of this pull request is accurate, we shouldn't be recreating it already)
There was a problem hiding this comment.
I wonder why we even open it for writing if we don't write to it?
There was a problem hiding this comment.
The information is not preserved: https://github.com/astral-sh/uv/pull/1782/changes
There was a problem hiding this comment.
I tried fs_err::OpenOptions::new().create_new(true).open(phony_git) and fs_err::OpenOptions::new().create(true).open(phony_git) but the error type isn't structured, we can't detect it reliably:
[crates/uv-cache/src/lib.rs:455:9] output = Err(
Custom {
kind: InvalidInput,
error: Error {
kind: OpenFile,
source: Custom {
kind: InvalidInput,
error: "creating or truncating a file requires write or append access",
},
path: "/home/konsti/.cache/uv/sdists-v9/.git",
},
},
)
error: Failed to initialize cache at `/home/konsti/.cache/uv`
Caused by: failed to open file `/home/konsti/.cache/uv/sdists-v9/.git`: creating or truncating a file requires write or append
access
There was a problem hiding this comment.
Turns out the reason is we fail if we don't have .write(true).
|
Unfortunately we can still hit the sandbox error in a race condition, which... seems rare but would be nice to avoid if we can. Could we just check if the file exists after we see an error then ignore the error if so? Also I presume if the file is missing we get a different error than if it exists but is read only? |
42927fd to
a014ae0
Compare
|
If the cache directory doesn't exist you get earlier failures, we fail to create No cache: Cache dir exists, but is empty: Whether |
The observable bug would be the same sandbox error that you're trying to fix. Don't we have a |
|
Can you describe the order of events that you see for this TUCTOU bug? Does it introduce any additional failure paths? |
|
No it doesn't introduce any new failure paths, but I don't understand the resistance to making the small change needed to avoid it? Do you want me to draft what I'm saying? The TOCTOU is A: Checks if the file exists -> no Where B has cache write permissions (i.e., not sandboxed), and A is sandboxed. |
|
e.g., why is 398a979 worse? |
a014ae0 to
c720cf2
Compare
|
I see, I don't think we can properly handle races between unsandboxed and sandboxed uv processes more generally (the sandboxed version fails or passes depending on the timing), but I agree that 398a979 is better code. |
c720cf2 to
88fb47a
Compare
sdist-vX/.git if it already existssdist-vX/.git if it already exists
zanieb
left a comment
There was a problem hiding this comment.
Yeah I agree the situation will be hard to handle robustly
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [uv](https://github.com/astral-sh/uv) | patch | `0.10.0` → `0.10.2` | 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 (uv)</summary> ### [`v0.10.2`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0102) [Compare Source](astral-sh/uv@0.10.1...0.10.2) Released on 2026-02-10. ##### Enhancements - Deprecate unexpected ZIP compression methods ([#​17946](astral-sh/uv#17946)) ##### Bug fixes - Fix `cargo-install` failing due to missing `uv-test` dependency ([#​17954](astral-sh/uv#17954)) ### [`v0.10.1`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0101) [Compare Source](astral-sh/uv@0.10.0...0.10.1) Released on 2026-02-10. ##### Enhancements - Don't panic on metadata read errors ([#​17904](astral-sh/uv#17904)) - Skip empty workspace members instead of failing ([#​17901](astral-sh/uv#17901)) - Don't fail creating a read-only `sdist-vX/.git` if it already exists ([#​17825](astral-sh/uv#17825)) ##### Documentation - Suggest `uv python update-shell` over `uv tool update-shell` in Python docs ([#​17941](astral-sh/uv#17941)) </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:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Ny4zIiwidXBkYXRlZEluVmVyIjoiNDIuOTcuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6OnBhdGNoIl19-->
Step 1 of N for readonly cache support. Moves the error message for LLM sandboxes from
sdist-vX/.gitto: