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] npm >= 9.6.7 does not pass signals to the running script #6547

Closed
2 tasks done
zdm opened this issue Jun 9, 2023 · 13 comments
Closed
2 tasks done

[BUG] npm >= 9.6.7 does not pass signals to the running script #6547

zdm opened this issue Jun 9, 2023 · 13 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@zdm
Copy link

zdm commented Jun 9, 2023

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

I have docker sontainer with nodejs application.
Application started using npm run prod command.
It starts script main.js.
This script waiting for SIGTERM and exits.

With npm <= 9.6.6 - when I send TERM signal, to the container it works as expected.
With npm >= 9.6.7 - main script just not receive signal.

Tested with all nom versions from 9.6.5 - 9.7.1.
Bug was introduced in v9.6.7.

Expected Behavior

Please, see above.

Steps To Reproduce

Please, see above.

Environment

  • npm:
  • Node.js:
  • OS Name: ubuntu
  • System Model Name:
  • npm config:
; copy and paste output from `npm config ls` here
@zdm zdm added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jun 9, 2023
@zdm
Copy link
Author

zdm commented Jun 9, 2023

This is major issue, that may lead to the data loss.

@zdm
Copy link
Author

zdm commented Jun 10, 2023

I created repo to reproduce this bug.

https://github.com/zdm/npm-issue-547

Please, see README..

Could you please fix it? This is very important for us.

@zdm
Copy link
Author

zdm commented Jun 12, 2023

Guys,
nom doesn't handle signals anymore.
This means that instead of correct exit on SIGTERM process will be killed after timeout.
This will lead to data loss on many applications.
Could you, please, restore correct functionality, as it was implemented in v9.6.6..

@tetsuharuohzeki
Copy link

I guess this is caused by:

@zdm
Copy link
Author

zdm commented Jun 16, 2023

Yes.
I am unable to contact person, who created this bug. He don't answer.

@zdm
Copy link
Author

zdm commented Jun 20, 2023

Is it possible to fix this?
Who ever decided to disable signals processing?

I am personally currently loaded on 200% and absolutely have no time to study and dig npm sources.

@zdm
Copy link
Author

zdm commented Jul 16, 2023

@wraithgar
Does this project has development team?
How bugs are fixed

@zdm
Copy link
Author

zdm commented Jul 25, 2023

This is complete shit.

@zdm zdm closed this as completed Jul 25, 2023
@ngbrown
Copy link

ngbrown commented Jul 28, 2023

I just encountered this in npm v9.6.7 after upgrading my docker container to node:18-bookworm-slim. Any call to npm run ... no longer passes SIGTERM through to the final script.

This was working in npm v8.19.4 that was shipped with node:16-bullseye-slim .

@ryanrasti
Copy link

I've run into the same issue in #6684 -- and it's more than signals are not passed to the final script: npm itself doesn't terminate when it receives a SIGTERM.

@ryanrasti
Copy link

@zdm I noticed you closed this bug -- is it fixed?

@dmaizel
Copy link

dmaizel commented Oct 18, 2023

Why was this closed?

@bencripps
Copy link

Could we reopen this issue, and merge npm/run-script#188

wraithgar pushed a commit to npm/run-script that referenced this issue Jan 3, 2024
## Description

This PR reverts the changes made in commit
`545f3be94d412941537ad0011717933d48cb58cf`, which inadvertently broke
signal forwarding to child processes (PR #142 ).
Contrary to the assumptions by @nlf , `SIGTERM` and similar signals are
not being correctly propagated to child processes. Instead, they are
only received by npm, resulting in incomplete signal handling.

The removal of signal forwarding in #142 means that child processes do
not receive necessary signals for appropriate cleanup and termination.

This issue is evident in workflows involving `npm start` used as a
Docker command for local execution. For instance, using CTRL + C does
not properly terminate the application
and results in a forced kill after a 10-second delay.

This behavior could lead to more significant problems in production
environments, (if `npm` is used to start the app) such as data loss due
to improper database connection closures.

## Minimal Reproduction Steps

Create a package.json with the following content:
```json
{
  "name": "npm",
  "scripts": {
    "start": "node ./main-test.js"
  }
}
```

Create a main-test.js file:
```typescript
const interval = setInterval(() => console.log('alive!'), 3000);

async function onSignal(signal) {
  console.log(`${signal} received, cleaning up...`);
  clearInterval(interval);
  console.log('Cleaning up done');
}
process.on('SIGINT', onSignal);
process.on('SIGTERM', onSignal);
```

Execute `npm start`. The script should output `alive!` every 3 seconds.
Attempt to terminate it using `kill -SIGTERM [PID]`.
It should log `Cleaning up done` and shut down gracefully,
which it does in older versions of `npm` (e.g., `v8.19.4`) but fails in
newer versions (e.g., `v9.6.7`).

## Impact
Reverting this change will restore the expected behavior for signal
handling in `npm`

# References

- npm/cli#6547
- npm/cli#6684
- #142
wraithgar pushed a commit to npm/run-script that referenced this issue Jan 3, 2024
This PR reverts the changes made in commit
`545f3be94d412941537ad0011717933d48cb58cf`, which inadvertently broke
signal forwarding to child processes (PR #142 ).
Contrary to the assumptions by @nlf , `SIGTERM` and similar signals are
not being correctly propagated to child processes. Instead, they are
only received by npm, resulting in incomplete signal handling.

The removal of signal forwarding in #142 means that child processes do
not receive necessary signals for appropriate cleanup and termination.

This issue is evident in workflows involving `npm start` used as a
Docker command for local execution. For instance, using CTRL + C does
not properly terminate the application
and results in a forced kill after a 10-second delay.

This behavior could lead to more significant problems in production
environments, (if `npm` is used to start the app) such as data loss due
to improper database connection closures.

Create a package.json with the following content:
```json
{
  "name": "npm",
  "scripts": {
    "start": "node ./main-test.js"
  }
}
```

Create a main-test.js file:
```typescript
const interval = setInterval(() => console.log('alive!'), 3000);

async function onSignal(signal) {
  console.log(`${signal} received, cleaning up...`);
  clearInterval(interval);
  console.log('Cleaning up done');
}
process.on('SIGINT', onSignal);
process.on('SIGTERM', onSignal);
```

Execute `npm start`. The script should output `alive!` every 3 seconds.
Attempt to terminate it using `kill -SIGTERM [PID]`.
It should log `Cleaning up done` and shut down gracefully,
which it does in older versions of `npm` (e.g., `v8.19.4`) but fails in
newer versions (e.g., `v9.6.7`).

Reverting this change will restore the expected behavior for signal
handling in `npm`

- npm/cli#6547
- npm/cli#6684
- #142
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 Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

6 participants