npm / npm/cli

[BUG] npm makes the child processes orphan on EACCES

Open
#7,053 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 1
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

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

When the npm CLI encounters an EACCES error due to a permissions issue, as shown below,

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /tmp/foo/bar/_cacache/tmp
npm ERR! errno -13
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 "/tmp/foo/bar"

npm ERR! Log files were not written due to an error writing to the directory: /tmp/foo/bar/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

the process invoked by npm becomes an orphan.

For instance, if npm start launches a daemon program, like an Express app, and npm terminates due to the same error, the npm process will exit with status 243, but the daemon program remains active.

The process tree initially looks like this:

1708440 pts/7    Ss     0:00 -bash
1714893 pts/7    Sl+    0:00  \_ npm start
1714922 pts/7    S+     0:00      \_ sh -c node --expose-gc app
1714923 pts/7    Rl+    0:00          \_ node --expose-gc app

becomes

1714922 pts/7    S      0:00 sh -c node --expose-gc app
1714923 pts/7    Rl     0:00  \_ node --expose-gc app

https://github.com/npm/cli/assets/1422834/02bf91b0-ce89-40ca-a1bd-ae629ea65656

Is this behavior intentional?

Expected Behavior

The invoked process by npm dies as well.

Steps To Reproduce
  1. Run npm with an inaccessible cache directory, for example, by using the nobody user or specifying an inaccessible directory for the cache parameter in .npmrc.
  2. Execute npm-related tasks.

I have created an example repository to facilitate easier reproduction. The Dockerfile outlines the environment and sets up a reproducible playground.

https://github.com/moznion/npm-orphan-example

Environment
  • npm: 10.2.4
  • Node.js: v20.10.0
  • OS Name: Linux 868d0296baea 6.2.0-37-generic #38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 2 18:01:13 UTC 2 x86_64 GNU/Linux
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
  • System Model Name: n/a
  • npm config:
; "user" config from /home/user/.npmrc

cache = "/tmp/inaccessible/.npm"

; node bin location = /usr/local/bin/node
; node version = v20.10.0
; npm local prefix = /home/user/npm-orphan-example
; npm version = 10.2.4
; cwd = /home/user/npm-orphan-example
; HOME = /home/user
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Dockerfile in the linked npm-orphan-example repository and reproduce the issue using an inaccessible cache directory or the nobody user. Observe the npm start process tree when npm exits with EACCES, then verify that the invoked process also terminates rather than becoming orphaned.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.