npm / npm/cli

[BUG] ctrl-c / SIGINT does not kill `npm install`

Open
#5,976 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug signals
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

Reproducible in npm 9.2.0 and 8.19.2

Killing the process with CTRL-C or sending SIGINT won't immediately kill npm. If I hit CTRL-C while the install progress bar is visible npm will continue running till the progress bar is full, including starting new http requests. Eventually npm will print

npm ERR! process terminated
npm ERR! signal SIGINT

Some excerpts from a silly log shows that npm runs for 12 seconds after the signal.

Dec 17 16:34:23 npm timing reifyNode:node_modules/esbuild-android-64 Completed in 48ms
Dec 17 16:34:23 SIGINT
Dec 17 16:34:24 npm http fetch POST 405 http://localhost:8080/-/npm/v1/security/advisories/bulk 305ms
...
Dec 17 16:34:24 npm http fetch GET 200 http://localhost:8080/rimraf 367ms (cache updated)
Dec 17 16:34:36 npm http fetch GET 200 http://localhost:8080/ansi-styles/-/ansi-styles-4.3.0.tgz 5860ms (cache updated)
Dec 17 16:34:36 npm timing reifyNode:node_modules/asse.rtion-error Completed in 12320ms
...
Dec 17 16:34:36 npm timing reify:unpack Completed in 12387ms
Dec 17 16:34:36 npm timing reify:rollback:createSparse Completed in 174ms
Dec 17 16:34:36 npm timing reify:rollback:retireShallow Completed in 11ms
Dec 17 16:34:36 npm timing command:install Completed in 12796ms
Dec 17 16:34:36 npm verb stack Error: process terminated

A second SIGINT signal will cause an immediate exit

Expected Behavior

Npm should exit soon after receiving SIGINT. If npm has to clean up after itself it should print a message - but it doesn't seem like it's cleaning up, instead it's continuing to fetch packages.

Steps To Reproduce
  1. On an Ubuntu linux computer with npm 9.2.0 or 8.19.2
  2. In a package with enough dependencies for npm install to take a while
  3. With a package-lock.json
  4. Without node_modules
  5. Run npm install
  6. Hit ctrl-c when you see the progress bar

See the progress bar continue and wait for npm to exit.

Interestingly it doesn't seem to reproduce without a package-lock.json.

Environment
  • npm: 9.2.0 (and 8.19.2)
  • Node.js: 18.12.1
  • OS Name: Ubuntu
  • System Model Name:
  • npm config:
; node version = v18.12.1
; npm local prefix = ~/example
; npm version = 8.19.2
; cwd = ~/example
; HOME = ~
; 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

Reproduce with npm 9.2.0 or 8.19.2 by running npm install in a package with package-lock.json and no node_modules, then press Ctrl-C at the progress bar. Compare behavior with and without package-lock.json and inspect the reported SIGINT timing. Done means npm exits soon after the signal without continuing package fetches, or clearly reports any cleanup it performs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.