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

luacheck: Fails due to cache write race condition #52

Closed
hunger opened this issue Mar 6, 2022 · 1 comment · Fixed by #56
Closed

luacheck: Fails due to cache write race condition #52

hunger opened this issue Mar 6, 2022 · 1 comment · Fixed by #56

Comments

@hunger
Copy link

hunger commented Mar 6, 2022

I am trying to use luacheck in pre-commit.ci and get a lot of false positives there.

This is the output I get:

[21 lines ending in ok]
Total: 0 warnings / 0 errors in 21 files
Critical error: Couldn't initialize cache in /tmp/cache/luacheck: Couldn't make directory /tmp/cache/luacheck: File exists

The devs over at pre-commit looked into the issue and came to the conclusion that luacheck is racing with its cache directory creation.

I can reproduce the same thing locally by repeatedly trying this command:

rm -rf ~/.cache/luacheck; PATH=$PWD/opt/lua/bin/:$PATH pre-commit run luacheck --all-files
please report the issue to luacheck

pointing to this code:

local function make_absolute_dirs(dir_path)
if fs.is_dir(dir_path) then
return true
end
local upper_dir = fs.normalize(fs.join(dir_path, ".."))
if upper_dir == dir_path then
return nil, ("Filesystem root %s is not a directory"):format(upper_dir)
end
local upper_ok, upper_err = make_absolute_dirs(upper_dir)
if not upper_ok then
return nil, upper_err
end
local make_ok, make_error = lfs.mkdir(dir_path)
if not make_ok then
return nil, ("Couldn't make directory %s: %s"):format(dir_path, make_error)
end
return true
end

This is the issue I raised with pre-commit.ci: pre-commit-ci/issues#114

@alerque
Copy link
Member

alerque commented Mar 7, 2022

Yes I see what the issues is ... Unfortunately the bug is even upstream of us, technically the lfs project needs a fix, anything else we can do is just a hack around the missing option there (raised upstream issue here).

In the mean time we can probably fudge and catch this particular error state, check again to see why we we ended up there, then hope for the best and go on. This isn't ideal though and I would suggest part of the problem is luacheck should be allowed to manage it's own threads instead of having them imposed. I'll raise that on the pre-check issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants