Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: Failed to initialize cache at <dir>/.ruff_cache: File exists (os error 17) #10880

Closed
pjonsson opened this issue Apr 11, 2024 · 1 comment · Fixed by #10884
Closed

error: Failed to initialize cache at <dir>/.ruff_cache: File exists (os error 17) #10880

pjonsson opened this issue Apr 11, 2024 · 1 comment · Fixed by #10884
Assignees
Labels
bug Something isn't working

Comments

@pjonsson
Copy link
Contributor

pjonsson commented Apr 11, 2024

Using Ruff 0.3.5 on Ubuntu 22.04 LTS, I just got this error:

<poetry install completes>
make[1]: Leaving directory '<dir>'
15 files already formatted
error: Failed to initialize cache at <dir>/.ruff_cache: File exists (os error 17)

This is the first time over hundreds of runs (Ruff 0.3.4/0.3.5), so unfortunately I don't have a reproducer.

This part of the setup is easy to explain though, I'm running multiple linters in parallel, these are the relevant parts of the Makefile:

lint: check format <other linters>

check:
        poetry run ruff check
format:
        poetry run ruff format --check --diff

and then make -j4 lint is called. The "make" is the GNU Make version 4.x that comes as a package in Ubuntu 22.04.

The non-Ruff linters (like mypy) are explicitly passed the subdirectories src tests so I do not believe they would create .ruff_cache or anything inside Ruff's cache directory at the project top level. All linters are configured to only report errors (so no --fix or similar is used), so the source code is not changed underneath the linters.

I managed to get a file listing from the machine before things were cleared:

user@<dir> $ ls -l .ruff_cache/
total 8
drwxr-xr-x 2 gitlab-runner gitlab-runner 4096 Apr 11 13:16 0.3.5
-rw-r--r-- 1 gitlab-runner gitlab-runner   43 Apr 11 13:16 CACHEDIR.TAG
user@<dir> $ ls -l .ruff_cache/0.3.5/
total 20
-rw------- 1 gitlab-runner gitlab-runner  204 Apr 11 13:16 10942930790367313274
-rw------- 1 gitlab-runner gitlab-runner  137 Apr 11 13:16 13043565573132441774
-rw------- 1 gitlab-runner gitlab-runner  436 Apr 11 13:16 16835848346372968819
-rw------- 1 gitlab-runner gitlab-runner 1547 Apr 11 13:16 2039258722430934445
-rw------- 1 gitlab-runner gitlab-runner  844 Apr 11 13:16 262724646336492797

I have no idea if the directory/files are as expected, but the file permissions look as I would expect them to look, and the machine has plenty of both inodes and space available.

@charliermarsh charliermarsh self-assigned this Apr 11, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Apr 11, 2024
@charliermarsh
Copy link
Member

Thanks, probably a rare race condition in the cache.

charliermarsh added a commit that referenced this issue Apr 11, 2024
## Summary

I believe this should close
#10880? The `.gitignore`
creation seems ok, since it truncates, but using `cachedir::is_tagged`
followed by `cachedir::add_tag` is not safe, as `cachedir::add_tag`
_fails_ if the file already exists.

This also matches the structure of the code in `uv`.

Closes #10880.
Glyphack pushed a commit to Glyphack/ruff that referenced this issue Apr 12, 2024
## Summary

I believe this should close
astral-sh#10880? The `.gitignore`
creation seems ok, since it truncates, but using `cachedir::is_tagged`
followed by `cachedir::add_tag` is not safe, as `cachedir::add_tag`
_fails_ if the file already exists.

This also matches the structure of the code in `uv`.

Closes astral-sh#10880.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants