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] ctrl-c / SIGINT does not kill npm install #5976

Open
2 tasks done
everett1992 opened this issue Dec 18, 2022 · 1 comment
Open
2 tasks done

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

everett1992 opened this issue Dec 18, 2022 · 1 comment
Labels
Bug thing that needs fixing signals

Comments

@everett1992
Copy link

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.
@everett1992 everett1992 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 Dec 18, 2022
@everett1992
Copy link
Author

everett1992 commented Dec 18, 2022

An interesting wrinkle is that npm will hang forever if it gets SIGINT and the registry server stops completing requests

This script starts a npm registry proxy and npm install process. ctrl-c sends SIGINT to both processes, killing the server but the install process never exits, it hangs with a broken progress bar. I assume npm would eventually exit after some timeout or the socket hangs up.

~/example » (###########⠂⠂⠂⠂⠂⠂⠂) ⠸ reify:@esbuild/android-arm: timing reifyNode:node_modules/@esbuild/linux-loong64 Comple(###########⠂⠂⠂⠂⠂⠂⠂) ⠸ reify:@esbuild/android-arm: timing reifyNode:node_modules/@esbuild/linux-loong64 Completed in 50ms

~/example » ps
1061916 pts/4    00:00:13 zsh
1278749 pts/4    00:00:01 npm install
1279015 pts/4    00:00:00 ps
import {request} from 'https';
import {createServer} from 'http';
import {spawn} from 'child_process';

const server = createServer()
  .listen(8080, 'localhost')
  .on('request', (req, res) => {
    const proxyReq = request(`https://registry.npmjs.com/${req.url}`, (proxyRes) => {
      res.writeHead(proxyRes.statusCode)
      proxyRes.pipe(res)
    })
    req.pipe(proxyReq)
  });
const proc = spawn('npm', ['install', '--registry', 'http://localhost:8080'], {stdio: 'inherit'})

proc.on('exit', () => server.close());

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

No branches or pull requests

2 participants