Skip to content

Implement a persist_with_retry feature, enabling more resiliency on Windows #316

@Coruscant11

Description

@Coruscant11

Hi!

While working with uv, I encountered issues with a python dependency, httpx unable to be installed because of a os error 5 permission denied.
The error occur when we try to persist a .exe file from a temporary folder into a persistent one.
I only reproduce the issue in an enterprise Windows Jenkins Runner. In my virtual machines, I don't have any issues. So I think this is most probably coming from the system configuration. (Antivirus I think).

Here is the function doing it: https://github.com/astral-sh/uv/blob/9864d23f48cfc00417d2969ef2ab6cdfda5bc084/crates/uv-install-wheel/src/wheel.rs#L427
It is using a NamedTempFile, coming from here: https://github.com/astral-sh/uv/blob/main/crates/uv-fs/src/lib.rs#L146

While doing some research and speaking with some colleagues (hi @vmeurisse), it seems that the issue is a very recurrent one on Windows.
In the Javascript ecosystem, there is this package, created by the @isaacs, npm inventor: https://www.npmjs.com/package/graceful-fs

The improvements are meant to normalize behavior across different platforms and environments, and to make filesystem access more resilient to errors.
One of its feature is this one:
On Windows, it retries renaming a file for up to one second if EACCESS or EPERM error occurs, likely because antivirus software has locked the directory.
I think it is most probably a way to solve our issue on Windows.
As you saw, uv is using the persist function, Here is the source: https://docs.rs/crate/tempfile/latest/source/src/file/imp/windows.rs#88
This function is performing a move, which is a rename right?

So I was wondering if, instead of just implementing a workaround on application side (uv), implementing a kind of persist with retry feature, as graceful-fs is doing, directly inside this crate would be a good idea? It would help a lot of people I think !

What do you think?
I of course volunteer to work on this 🙂 I will try a draft pull-request in the meantime in order to validate my fix.

Thanks, and thanks again for this crate!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions