This is a demo repo to show a bug in npm where signals are not forwarded to the underlying process:
This bug appears in NPM >=9.6.7 <10.3.0
.
We have a single entrypoint at src/index.js
which sets a long timer and clears the timer whenever a kill signal is received. We execute this file using 3 different techniques:
node ./src/index.js
npm start
(executes the same command above)npx -y tsx ./src/index.js
We use docker compose to execute each of the above commands in multiple versions of node with different versions of npm. Docker will send SIGTERM to all services when you stop the cluster. Docker will forceably terminate any process which hasn't gracefully exited after ~10s.
docker compose up
# Then stop it using CTRL + C
...or
docker compose up -d
docker compose stop
- Running a process directly with
node ...
works as expected in all scenarios. - Any version of npm
>=9.6.7 <10.3.0
will show the bug when you start the process withnpm
ornpx
executables.