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 kills NPM while the Node app keeps running in the background #7511

Open
2 tasks done
noseratio opened this issue May 12, 2024 · 0 comments
Open
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@noseratio
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

On Windows, if Node.js app handles SIGINT, npm exits before the Node app does:

delay.mjs:

process.on('SIGINT', () => {
  console.log("ctrl+c pressed");
});

console.log("sleeping...");
await new Promise(r => setTimeout(r, 5000));
console.log("exiting gracefully");

package.js:

{
  "name": "ctrl-c",
  "main": "delay.mjs",
  "scripts": {
    "start": "node delay.mjs"
  }
}

Running it:

PS C:\temp\ctrl-c> npm start
> start
> node delay.mjs
sleeping...
ctrl+c pressed
PS C:\temp\ctrl-c> exiting gracefully

PS C:\temp\ctrl-c>

Note how the Node app still writes to the console after npm has terminated.

Expected Behavior

The desired behavior is as on Linux, where npm exits only when the Node app has ended.

Steps To Reproduce

See above

Environment

  • npm:
    v10.7.0

  • Node.js:
    v22.1.0

  • OS Name:
    Microsoft Windows 11 Pro [Version 10.0.22631.3527]

  • PowerShell:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
  • npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\Master\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v22.1.0
; npm local prefix = C:\temp\ctrl-c
; npm version = 10.7.0
; cwd = C:\temp\ctrl-c
; HOME = C:\Users\Master
; Run `npm config ls -l` to show all defaults.
@noseratio noseratio added Bug thing that needs fixing Needs Triage needs review for next steps labels May 12, 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 Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

1 participant