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] NPM crashes when no access to cache directory, but has access to registry. #6245

Closed
2 tasks done
lluio opened this issue Mar 13, 2023 · 2 comments
Closed
2 tasks done
Assignees
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release

Comments

@lluio
Copy link

lluio commented Mar 13, 2023

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

This previous issue (#4996, fixed by #5197) is still relevant. If the npm cache directory is invalid (e.g. /dummy), but npm does not have access to the registry (behind proxy, or npm_config_offline=true), the ENOENT error is logged, but the app does not crash. If npm does have access to registry, it logs the error and then crashes.

I am, additionally, curious why npm is connecting to the registry at all just because the default cache dir is restricted. I.e:

  • With a valid directory, no http-request is logged with NODE_DEBUG=http
  • With an illegal directory (e.g. /dummy) the node debug logs show that a GET request is being sent to registry.npmjs.org

Expected Behavior

NPM should not crash with an invalid cache-location just because it has access to the registry. This should, like in #5197, be logged silently as an error and not cause the program to crash.

Steps To Reproduce

  1. Using [email protected] and [email protected]
  2. Run a basic npm script, such as this:
{
  "scripts": {
    "dummy": "echo 'hello' && sleep 2 && echo 'Yeet!'"
  }
}
  1. With access to registry.npmjs.org, run this command:
npm_config_cache=/123 npm run dummy --loglevel=silly
  1. This error is logged:
npm verb cli /home/.../.nvm/versions/node/v18.15.0/bin/node /home/.../.nvm/versions/node/v18.15.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verb cache could not create cache: Error: EACCES: permission denied, mkdir '/123'
npm verb logfile could not create logs-dir: Error: EACCES: permission denied, mkdir '/123'
npm verb title npm run dummy
npm verb argv "run" "dummy" "--loglevel" "silly"
npm verb logfile logs-max:10 dir:/123/_logs/2023-03-13T12_57_20_721Z-
npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/123/_logs/2023-03-13T12_57_20_721Z-debug-0.log'
npm verb logfile no logfile created
npm sill logfile done cleaning log files

> dummy
> echo 'hello' && sleep 2 && echo 'Yeet!'

hello
npm verb stack Error: EACCES: permission denied, mkdir '/123'
npm verb cwd /home/.../temp
npm verb Linux 5.19.0-35-generic
npm verb node v18.15.0
npm verb npm  v9.6.1
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /123
npm ERR! errno -13
npm verb Error: EACCES: permission denied, mkdir '/123' 
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/123"
npm verb exit -13
npm verb unfinished npm timer command:run 1678712240740
npm verb code -13

npm ERR! Log files were not written due to an error writing to the directory: /123/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
  1. Just to demonstrate, now run with npm_config_offline=true, and it runs with the following output:
npm verb cli /home/.../.nvm/versions/node/v18.15.0/bin/node /home/.../.nvm/versions/node/v18.15.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verb cache could not create cache: Error: EACCES: permission denied, mkdir '/123'
npm verb logfile could not create logs-dir: Error: EACCES: permission denied, mkdir '/123'
npm verb title npm run dummy
npm verb argv "run" "dummy" "--loglevel" "silly"
npm verb logfile logs-max:10 dir:/123/_logs/2023-03-13T12_58_32_261Z-
npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/123/_logs/2023-03-13T12_58_32_261Z-debug-0.log'
npm verb logfile no logfile created
npm sill logfile done cleaning log files

> dummy
> echo 'hello' && sleep 2 && echo 'Yeet!'

hello
Yeet!
npm verb exit 0
npm info ok 

Environment

  • npm: 9.6.1
  • Node.js: 18.15.0
  • OS Name: Ubuntu Linux
  • npm_config_cache set to unpermitted directory, such as /dummy.
@lluio lluio added Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release labels Mar 13, 2023
@mvorisek
Copy link

mvorisek commented May 17, 2023

I am facing this problem as well:

npm ERR! code 243
npm ERR! git dep preparation failed
npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/github/home/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm ERR! code EACCES
npm ERR! npm ERR! syscall open
npm ERR! npm ERR! path /github/home/.npm/_cacache/index-v5/c3/24/3bcf5990edce4f749f04b7e4602dae2ed3f0eb3e28ceffb776d0c623cce6
npm ERR! npm ERR! errno -13
npm ERR! npm ERR! 
npm ERR! npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! npm ERR! previous versions of npm which has since been addressed.
npm ERR! npm ERR! 
npm ERR! npm ERR! To permanently fix this problem, please run:
npm ERR! npm ERR!   sudo chown -R 1001:123 "/github/home/.npm"
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /github/home/.npm/_logs/2023-05-17T11_18_34_563Z-debug-0.log
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.

log part is interesting, as run on clean Docker image /wo any populated cache and the problem is appearing randomly in about 1 of 5 runs. It seems like some race condition.

steps to reproduce:

  1. use ghcr.io/mvorisek/image-php:8.0-selenium Docker image (basically a clean Alpine with node/npm - https://github.com/mvorisek/image-php/blob/3a4165d67e/data/8.0-alpine/Dockerfile)
  2. checkout https://github.com/atk4/ui/tree/62020d257cf5f55b4d490f636808ab4d7f4bf372/js
  3. cd js && npm install --package-lock-only --save-dev babel-plugin-istanbul nyc && npm ci --loglevel=error
  4. as the problem does not appear always, run it like 1000 times /wo Docker caching and you should be able to reproduce it

@lukekarrys
Copy link
Contributor

This was fixed by c7a592c as part of [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release
Projects
None yet
Development

No branches or pull requests

3 participants