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

SIGINT closes the yarn process, but actual nodejs process is still running #8895

Open
hasezoey opened this issue Oct 25, 2022 · 6 comments
Open

Comments

@hasezoey
Copy link

I have run into a weird issue where i want to listen on SIGINT and have confirmation that it should be closed (by pressing it again), but when run through yarn, it exits the yarn process but leaves the nodejs process behind.

yarn package.json script:

{
  "scripts": { "run": "node lib/bin.js" }
}

test code:

process.on('SIGINT', () => {
  console.log("sigint");
})

setInterval(() => {
  console.log("interval");
}, 1000 * 2); // 2 seconds

Behavior in yarn: once pressing CTRL+C, then it logs sigint once, and drops me to the shell, but the nodejs process is still running and outputting things as seen by subsequent interval
Behavior in plain node: always when pressing CTRL+C it will trigger sigint and does not drop me to the shell

System:
Node: 18.10.0
Yarn: 1.22.19
Linux 6.0.2 Manjaro

@ppedziwiatr
Copy link

shouldn't the handler for SIGINT contain the process.exit(0) after the console.log?

@hasezoey
Copy link
Author

shouldn't the handler for SIGINT contain the process.exit(0) after the console.log?

SIGINT (or SIGTERM) does not mean it needs to immediately exit unlike other events like beforeExit
and the problem is that yarn exists while still leaving the node process of the actual process orphaned on a SIGINT (and SIGTERM), unless those signals are directly send to the nodejs process via kill, but SIGINT is sent to the yarn process when pushing CTRL+C on the console

@DaThresh
Copy link

I believe I have run into this issue as well. I have a Typescript server that when I run it directly with ts-node ./server/server, when signaling SIGINT via Ctrl+C, my graceful shutdown code is run and exit code is 0 (can be checked by running echo $? directly after exit).

This is the exact same script that I've put in my package.json's "start", and when running yarn start I can see it's running the same command. However, when I send SIGINT via Ctrl+C, exit code delivered to my console is 130.

@ABCxFF
Copy link

ABCxFF commented Jul 12, 2023

Am also encountering this same aggravating issue; I'm hoping to find command line flag that could fix. Hope this is fixed soon

@KhaledElmorsy
Copy link

Also encountering this issue.

@mdevils
Copy link

mdevils commented Nov 7, 2024

Here is a PR to fix this issue: #9114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants