[BUG] npm not handling process signals
Nobody has claimed this yet.
- 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
NOTE: I originally posted this issue on nodejs/node but was redirected here.
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
npm doesn't handle SIGTERM like it used to. I noticed this issue specifically when updating node from v20.2.0 to v20.3.0 (npm 9.6.7 to 9.8.1).
Expected Behavior
Expected that the below program exits with code 0 (i.e., npm is aborted by the signal and the script handles the signal as well)
Steps To Reproduce
The below script sends a SIGTERM to the npm process that spawned it. Run npm run test with:
In package.json
{
"name": "test",
"version": "0.0.0",
"type": "module",
"scripts": {
"test": "node test.js"
}
}
In test.js
import { execSync } from 'child_process';
process.on('SIGTERM', () => {
console.log('Received SIGTERM. Exiting...');
process.exit(0);
});
const output = execSync('ps -e | grep npm').toString().split(/\s+/).filter(Boolean);
const pid = Number(output[0]);
process.kill(pid)
setTimeout(() => {
console.log('Fatal: Signal was not received. Exiting... ');
process.exit(1)
}, 2000);
Environment
- npm: 9.8.0
- Node.js: v20.5.0
- OS Name: Linux nixos 5.15.93 x86_64 GNU/Linux
- System Model Name:
- npm config:
; node bin location = /nix/store/1gnvy2dhh311c900hzyw6ppjdhnir2s5-nodejs-20.5.0/bin/node
; node version = v20.5.0
; npm local prefix = /build
; npm version = 9.8.0
; cwd = /build
; HOME = /homeless-shelter
; Run `npm config ls -l` to show all defaults.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running npm run test with the package.json and test.js reproduction on Linux, then trace how the npm process handles the SIGTERM sent by the script. Done means npm is aborted by the signal, the script's SIGTERM handler logs its message, and the program exits with code 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100