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

[BUG] lchown error when accessing installation lock file when running multiple installations in parallel. #496

Closed
SimonSchick opened this issue Nov 18, 2019 · 16 comments · Fixed by SUI-Components/sui#719 or isaacs/chownr#22

Comments

@SimonSchick
Copy link

What / Why

NPM fails to due to create(?) locks (not package-lock.json) during installation.

When

  • Appears to happen when performing multiple parallel installs.

Where

How

Current Behavior

  • Will occassionally fail to lchown npm lock files (not package-lokc.json).

Steps to Reproduce

  • See where section.
  • It is possible to repro this by performing the following steps:
    • Clone my fork of DT and checkout my branch related to this PR
    • Initialise via npm install
    • Run npm test node

Expected Behavior

  • Locking does not failed.

Who

  • Unsure

References

@SimonSchick SimonSchick changed the title [BUG] <title> [BUG] lchown error when accessing installation lock file when running multiple installations in parallel. Nov 18, 2019
@sandersn
Copy link
Contributor

Also occurs locally on Linux with the same repro steps, eg

npm ERR! syscall lchown
npm ERR! path /home/nathansa/.npm/_locks/staging-33722a1ecded5100.lock
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, lchown '/home/nathansa/.npm/_locks/staging-33722a1ecded5100.lock'
npm ERR! enoent This is related to npm not being able to find a file.

@sandersn
Copy link
Contributor

Seems to happen less when I switch to node 11.0.0 + npm 6.7.0.

@Flarna
Copy link

Flarna commented Nov 22, 2019

Node 11.0.0 is a really strange version as node 11 is EOL since a while. Maybe try the current LTS 12.13.1? Or it's maybe the older NPM version bundled with node 11 which avoids this.

@sandersn
Copy link
Contributor

Yeah, I was just travelling backward through the versions I have installed until I found a non-problematic version. The older npm version is very likely the variable.

@SimonSchick
Copy link
Author

@sandersn maybe perform a manual binary search through versions? 😛

@Cawllec
Copy link

Cawllec commented Dec 11, 2019

Experiencing this bug when using Lerna consistently, which is unfortunately causing issues in our build process.
Error message:

lerna ERR! npm install stderr:
  | npm ERR! code ENOENT
  | npm ERR! syscall lchown
  | npm ERR! path /root/.npm/_locks/staging-3f138bd09ee0de58.lock
  | npm ERR! errno -2
  | npm ERR! enoent ENOENT: no such file or directory, lchown '/root/.npm/_locks/staging-3f138bd09ee0de58.lock'
  | npm ERR! enoent This is related to npm not being able to find a file.
  | npm ERR! enoent

This is when using the node:latest-alpine docker image, which currently uses the versions:
node: 12.13.1
npm: 6.12.1

@midudev
Copy link

midudev commented Dec 19, 2019

I can confirm this is happening to me as well with node v13.2.0 and npm 6.13.4.

Anyone has a temporary fix for this? As it's blocking some of our deployments. :(

@SimonSchick
Copy link
Author

@midudev temp mitigation is to not run npm i in parallel or at least drastically reduce concurrency.
When dealing with the DT repo limiting it to 2 parallel installs it reduced the amount of failures by about ~90%.

@midudev
Copy link

midudev commented Dec 20, 2019

Thanks @SimonSchick. Yes... Using no concurrency at all seems to fix the problem but the time needed for installing packages is vastly increased. :(

I wonder if the npm team is aware of this problem as this was working fine previously. Of if this is a problem caused because some inner changes on node.

@yavorski
Copy link

yavorski commented Jan 15, 2020

Hi, we have the same issue.
I am almost sure that this is some kind of race condition issue.

Temporary fix is to downgrade to npm@6.10.1.

I have tested almost every version from 6.10.2 to latest 6.13.6 and the issue is there.
I can confirm the bug is NOT related to the nodejs version, it's just related to npm version.

@raymondfeng
Copy link
Contributor

We're experiencing the same issue for npm i against https://github.com/strongloop/loopback-next, which is a lerna monorepo. npm i at the root level triggers npm installation for multiple packages in parallel. Reducing the concurrency also reduces the chance of running the reported issue.

@raymondfeng
Copy link
Contributor

We can get more information about the lockfile with NODE_DEBUG=lockfile npm i.

@raymondfeng
Copy link
Contributor

raymondfeng commented Jan 28, 2020

After some debugging, I found the issue around https://github.com/npm/cli/blob/latest/lib/utils/correct-mkdir.js#L31. If npm is executed concurrently, multiple processes call chownr against ~/.npm/_locks. The implementation of chownr reads all files in the directory and try to apply chown against each of the files. Some of the files might be deleted between readdir and lchown and it leads to ENOENT.

raymondfeng added a commit to raymondfeng/chownr that referenced this issue Jan 28, 2020
Some files might be deleted during chownr. This commit ignore ENOENT
errors to tolerate such cases to mimic 'chown -R'.

Fixes npm/cli#496
@raymondfeng
Copy link
Contributor

@isaacs Please let me know if raymondfeng/chownr@e4c7b59 is the right place to fix this issue. If so, I'll try to add some tests and submit a PR.

@isaacs
Copy link
Contributor

isaacs commented Jan 29, 2020

@raymondfeng That looks like a reasonable change. Yes, please do send a PR to chownr.

raymondfeng added a commit to raymondfeng/chownr that referenced this issue Jan 29, 2020
Some files might be deleted during chownr. This commit ignore ENOENT
errors to tolerate such cases to mimic 'chown -R'.

Fixes npm/cli#496
raymondfeng added a commit to raymondfeng/chownr that referenced this issue Jan 29, 2020
Some files might be deleted during chownr. This commit ignore ENOENT
errors to tolerate such cases to mimic 'chown -R'.

Fixes npm/cli#496
@raymondfeng
Copy link
Contributor

@isaacs PR submitted - #496. Thank you for the prompt response.

raymondfeng added a commit to raymondfeng/chownr that referenced this issue Jan 30, 2020
Some files might be deleted during chownr. This commit ignore ENOENT
errors to tolerate such cases to mimic 'chown -R'.

Fixes npm/cli#496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants