cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] Improper handling of graceful exits with `npx`

Open greguz opened this issue 11 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

This issue exists in the latest npm version

  • [x] I am using the latest npm

Current Behavior

Sending a SIGINT signal using npx node anything.js will result in a double SIGINT received by the application code.

Expected Behavior

Just one signal to be received by the application code.

Steps To Reproduce

console.log('starting up')

process.on('SIGINT', () => {
  console.log('shutting down')

  // simulate cleanup
  setTimeout(() => {
    console.log('cleanly exiting')
    process.exit(0)
  }, 5000)
})

// run forever
setInterval(() => {}, 1 << 30)
╭─greguz@prunix ~/Development/issue 
╰─$ npx node z.js
starting up
^Cshutting down
shutting down
cleanly exiting

Environment

  • npm: v11.2.0
  • Node.js: v23.10.0
  • OS Name: macOS 15.3.2 (24D81)
  • System Model Name: Apple M2 Pro
  • npm config:
; "user" config from /Users/greguz/.npmrc

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /Users/greguz/.local/share/fnm/node-versions/v23.10.0/installation/bin/node
; node version = v23.10.0
; npm local prefix = /Users/greguz/Development/evologi/orderpod-dlr
; npm version = 11.2.0
; cwd = /Users/greguz/Development/evologi/orderpod-dlr
; HOME = /Users/greguz
; Run `npm config ls -l` to show all defaults.

greguz avatar Mar 14 '25 11:03 greguz

We have similer issue raised and triaged in past where npm was handling signals like SIGINT twice https://github.com/npm/cli/issues/5021

milaninfy avatar Mar 18 '25 21:03 milaninfy

The fact that #5021 is still open doesn't make me feel any better 🙃

greguz avatar Mar 24 '25 16:03 greguz

I recently switched back to npx because this bug was occurring within pnpm alone at the time (see: https://github.com/pnpm/pnpm/issues/7374). This separate from the double-sending SIGINT issue or (worryingly) indicates that fixes that previously worked for that issue no longer work for some reason.

joshualip-plaudit avatar Aug 04 '25 19:08 joshualip-plaudit