yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.4k stars 2.73k forks source link

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

Open hasezoey opened 1 year ago

hasezoey commented 1 year ago

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 commented 1 year ago

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

hasezoey commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

KhaledElmorsy commented 1 year ago

Also encountering this issue.