concurrently: SIGINT is sent twice when pressing Ctrl-C, causing dirty shutdown
I have a package.json with the following scripts:
…
"startemulators": "firebase emulators:start --import seed",
"listen": "onchange 'source_files/*.js' -- touch functions/index.js",
"emulate": "concurrently \"npm run startemulators\" \"npm run listen\""
…
Running the emulate script works as expected, but pressing Ctrl-C to shut the processes down gives me this:
[0] i emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
[0] i emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
[0] i emulators: Shutting down emulators.
[0] i ui: Stopping Emulator UI
[0] ⚠ Emulator UI has exited upon receiving signal: SIGINT
[0] i functions: Stopping Functions Emulator
[0] i hosting: Stopping Hosting Emulator
[0] i database: Stopping Database Emulator
[1] npm run listen exited with code 0
[0]
[0] ⚠ emulators: Received SIGINT (Ctrl-C) 2 times. You have forced the Emulator Suite to exit without waiting for 3 subprocesses to finish.
So for some reason, a second SIGINT is sent to the firebase command specified in the first script. How come?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 17
- Comments: 19 (1 by maintainers)
Commits related to this issue
- removed double kill command on exit, as per https://github.com/open-cli-tools/concurrently/issues/283\#issuecomment-878452792 — committed to fcamblor/concurrently by fcamblor 3 months ago
- fixing concurrently bug which was not letting enough time to firebase emulators to persist data (see https://github.com/open-cli-tools/concurrently/issues/283\#issuecomment-878452792) — committed to voxxrin/voxxrin3 by fcamblor 3 months ago
Hi,
I have the same problem and investigated a little bit. By commenting out that line, I ended up with something working correctly, no double
SIGINT, everything is cool.It looks like
spawn-commanddoes not spawn the subprocess in detached mode, and it seems the defaults in concurrently are not setting detached options neither. Because if not, it’s perfectly normal to have theSIGINTsent twice, because it’s received by the subprocess, and then resent withcommand.kill(signal)a second time.Running into this problem myself, here’s a bit from my
package.json:If I run
npm run serveand then press Ctrl+C the Firebase emulators see double SIGINT signals and shutdown without exporting data.I think this may be due to Concurrently’s use of
tree-killto terminate individual processes. For example, if you send a SIGINT signal to a Docker Compose, it will handle terminating its subprocesses on its own; there’s no need for Concurrently to know or care that the process has subprocesses (although I’m sure that’s not always the case). But I think having the option to override this behaviour with simply sending the signal to each of the original processes might solve this issue.I wanted to verify this by writing a minimal wrapper for the Concurrently API and passing
(pid, signal) => process.kill(pid, signal)as thekilloption; but it doesn’t quite seem to work as it should - there’s no output at all (even when I passoutputStream: process.stdoutin the options), and the script seems to terminate immediately when I hit Ctrl+C, as opposed to waiting for the child processes to exit, like the CLI does; so I don’t really know how to verify this.@jasonkylefrank kind of - i am running the emulators outside of
concurrentlybut my servers are still running viaconcurrentlyas for windows - i don’t use windows so idk lol
@gustavohenke I moved from
concurrentlyto Docker Containers last year, and that removed the dirty shutdown issue for me.hi there! I’m experiencing this issue too if I try to run
firebasedirectly asconcurrentlycommand.However, if my
firebasecommand is wrapped withyarnscript command inpackage.json, the issue is not reproduced. Looks likeyarnalready does some protection of double sent signals.I can’t use full command in scripts since I construct
firebasecommand args on the fly. So I did an alias like that:and then call the command via
concurrentlylike that:for me this is a legit workaround, hope it helps someone else
I have not been able to create a small test case that consistently shows this error, but I have discovered that skipping the pubsub emulator makes the error go away. For example, using this:
firebase emulators:start --only firestore,database,functions,hosting,pubsubwill send SIGINT twice when quitting concurrently, while this:
firebase emulators:start --only firestore,database,functions,hostingwill not.
The positive case comes here.
If I launch: concurrently -> Docker -> Firebase CLI (which I do in a web app project, all the time), the double Ctrl-C occurs.
Detailed log
Note: This is just my 2c. I am not really troubled by this error message, since if running things under Docker, things get cleaned up, anyhow.