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

No graceful exit using NPM Scripts #2507

Closed
kellyjandrews opened this issue Jul 30, 2020 · 9 comments · Fixed by #2517
Closed

No graceful exit using NPM Scripts #2507

kellyjandrews opened this issue Jul 30, 2020 · 9 comments · Fixed by #2517

Comments

@kellyjandrews
Copy link

[REQUIRED] Environment info

firebase-tools: 8.6.0

Platform: macOS

[REQUIRED] Test case

Setup a firebase project that uses the emulators.

[REQUIRED] Steps to reproduce

Start the emulators through npm start. I'm currently using hosting, functions and firestore.

    "start": "GOOGLE_APPLICATION_CREDENTIALS=/google-creds.json firebase emulators:start --import=./data --export-on-exit"

Stop emulators using CTRL-C

[REQUIRED] Expected behavior

A graceful exit.

i  emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i  emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i  Automatically exporting data using --export-on-exit "./data" please wait for the export to finish...
i  Found running emulator hub for project emulator-test at http://localhost:4400
i  Deleting directory /emulator-test/functions/data/firestore_export
i  Exporting data to: /emulator-test/functions/data
i  emulators: Received export request. Exporting data to /emulator-test/functions/data.
✔  emulators: Export complete.
✔  Export complete
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
i  ui: Stopping Emulator UI
i  logging: Stopping Logging Emulator
i  functions: Stopping Functions Emulator
i  firestore: Stopping Firestore Emulator
i  hosting: Stopping Hosting Emulator

[REQUIRED] Actual behavior

i  emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i  emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i  Automatically exporting data using --export-on-exit "./data" please wait for the export to finish...
 
⚠  emulators: Received SIGINT (Ctrl-C) 2 times. You have forced the Emulator Suite to exit without waiting for 2 subprocesses to finish. These processes may still be running on your machine: 

┌────────────────────┬────────────────┬──────┐
│ Emulator           │ Host:Port      │ PID  │
├────────────────────┼────────────────┼──────┤
│ Emulator UI        │ localhost:4003 │ 1818 │
├────────────────────┼────────────────┼──────┤
│ Firestore Emulator │ localhost:4001 │ 1818 │
└────────────────────┴────────────────┴──────┘

To force them to exit run:

kill 1818 1818

Ironically, with --debug it does not fail.

i  emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown. 
i  emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now. 
i  Automatically exporting data using --export-on-exit "./data" please wait for the export to finish... 
[2020-07-30T13:06:48.536Z] >>> HTTP REQUEST GET http://localhost:4400/  
 
[2020-07-30T13:06:48.540Z] [worker-~diagnostic~-9bb61cf1-df1d-41d7-9e2a-fba05b969819]: exited {"metadata":{"emulator":{"name":"functions"},"message":"[worker-~diagnostic~-9bb61cf1-df1d-41d7-9e2a-fba05b969819]: exited"}}
[2020-07-30T13:06:48.541Z] [worker-~diagnostic~-9bb61cf1-df1d-41d7-9e2a-fba05b969819]: FINISHED {"metadata":{"emulator":{"name":"functions"},"message":"[worker-~diagnostic~-9bb61cf1-df1d-41d7-9e2a-fba05b969819]: FINISHED"}}
[2020-07-30T13:06:48.546Z] <<< HTTP RESPONSE 200 {"x-powered-by":"Express","content-type":"application/json; charset=utf-8","content-length":"50","etag":"W/\"32-awxJiFDOu9uUeUgx8zcVKrDfcNg\"","date":"Thu, 30 Jul 2020 13:06:48 GMT","connection":"keep-alive"}
i  Found running emulator hub for project kja-emulator-example at http://localhost:4400 
i  Deleting directory /Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data/firestore_export 
i  Exporting data to: /Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data 
[2020-07-30T13:06:48.555Z] >>> HTTP REQUEST POST http://localhost:4400/_admin/export  
 {"path":"/Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data"}
i  emulators: Received export request. Exporting data to /Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data. 
[2020-07-30T13:06:48.579Z] >>> HTTP REQUEST POST http://localhost:4001/emulator/v1/projects/kja-emulator-example:export  
 {"database":"projects/kja-emulator-example/databases/(default)","export_directory":"/Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data","export_name":"firestore_export"}
[2020-07-30T13:06:48.695Z] Jul 30, 2020 9:06:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
 {"metadata":{"emulator":{"name":"firestore"},"message":"Jul 30, 2020 9:06:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
[2020-07-30T13:06:48.729Z] Jul 30, 2020 9:06:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
 {"metadata":{"emulator":{"name":"firestore"},"message":"Jul 30, 2020 9:06:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected HTTP/2 connection.\n"}}
[2020-07-30T13:06:48.834Z] Jul 30, 2020 9:06:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
 {"metadata":{"emulator":{"name":"firestore"},"message":"Jul 30, 2020 9:06:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
[2020-07-30T13:06:50.151Z] <<< HTTP RESPONSE 200 {"content-type":"application/json","content-length":"4"}
✔  emulators: Export complete. 
[2020-07-30T13:06:50.154Z] <<< HTTP RESPONSE 200 {"x-powered-by":"Express","content-type":"application/json; charset=utf-8","content-length":"16","etag":"W/\"10-MxB4y4MLcx6QDsp8b8vgp7iFMFo\"","date":"Thu, 30 Jul 2020 13:06:50 GMT","connection":"keep-alive"}
✔  Export complete 
i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
i  hub: Stopping emulator hub {"metadata":{"emulator":{"name":"hub"},"message":"Stopping emulator hub"}}
i  ui: Stopping Emulator UI {"metadata":{"emulator":{"name":"ui"},"message":"Stopping Emulator UI"}}
i  logging: Stopping Logging Emulator {"metadata":{"emulator":{"name":"logging"},"message":"Stopping Logging Emulator"}}
i  functions: Stopping Functions Emulator {"metadata":{"emulator":{"name":"functions"},"message":"Stopping Functions Emulator"}}
i  firestore: Stopping Firestore Emulator {"metadata":{"emulator":{"name":"firestore"},"message":"Stopping Firestore Emulator"}}
i  hosting: Stopping Hosting Emulator {"metadata":{"emulator":{"name":"hosting"},"message":"Stopping Hosting Emulator"}}
[2020-07-30T13:06:50.166Z] *** shutting down gRPC server since JVM is shutting down
 {"metadata":{"emulator":{"name":"firestore"},"message":"*** shutting down gRPC server since JVM is shutting down\n"}}
⚠  Emulator UI has exited upon receiving signal: SIGINT 
[2020-07-30T13:06:50.169Z] *** server shut down
 {"metadata":{"emulator":{"name":"firestore"},"message":"*** server shut down\n"}}
[2020-07-30T13:06:50.224Z] File /Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data/firebase-export-metadata.json changed, reloading triggers {"metadata":{"emulator":{"name":"functions"},"message":"File /Users/kellyjandrews/Google Drive/Apps/emulator-test/functions/data/firebase-export-metadata.json changed, reloading triggers"}}

Not sure why it's getting the second SIGINT, or if there is any way to prevent it from happening. Let me know if there is something I can change on my end to fix it directly as well. Thanks!

@kellyjandrews kellyjandrews changed the title NPM Not gracefully exiting No gracefully exit using NPM Scripts Jul 30, 2020
@kellyjandrews kellyjandrews changed the title No gracefully exit using NPM Scripts No graceful exit using NPM Scripts Jul 30, 2020
@samtstern
Copy link
Contributor

@kellyjandrews hmmm I am not able to reproduce this, here are my logs:

$ firebase emulators:start --export-on-exit ./data
i  emulators: Starting emulators: functions, firestore
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: database, hosting, pubsub
✔  functions: Using node@10 from host.
i  firestore: Firestore Emulator logging to firestore-debug.log
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "/private/var/folders/xl/6lkrzp7j07581mw8_4dlt3b000643s/T/tmp.8SOVRn4y/functions" for Cloud Functions...

┌───────────────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! View status and logs at http://localhost:4000 │
└───────────────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Other reserved ports: 4400, 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

^C
i  emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i  emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i  Automatically exporting data using --export-on-exit "./data" please wait for the export to finish...
i  Found running emulator hub for project fir-dumpster at http://localhost:4400
i  Deleting directory /private/var/folders/xl/6lkrzp7j07581mw8_4dlt3b000643s/T/tmp.8SOVRn4y/data/firestore_export
i  Exporting data to: /private/var/folders/xl/6lkrzp7j07581mw8_4dlt3b000643s/T/tmp.8SOVRn4y/data
i  emulators: Received export request. Exporting data to /private/var/folders/xl/6lkrzp7j07581mw8_4dlt3b000643s/T/tmp.8SOVRn4y/data.
✔  emulators: Export complete.
✔  Export complete
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
i  ui: Stopping Emulator UI
i  logging: Stopping Logging Emulator
i  functions: Stopping Functions Emulator
i  firestore: Stopping Firestore Emulator
⚠  Emulator UI has exited upon receiving signal: SIGINT

It does seem like a bug that you're getting the same PID for all emulators though ...

samtstern added a commit that referenced this issue Jul 31, 2020
@samtstern
Copy link
Contributor

Fixing the wrong PID issue in #2511 ... still not sure why you're seeing double Ctrl+C though. Is it possible it's your Macbook keyboard acting up? Mine does double keypresses all the time.

@kellyjandrews
Copy link
Author

When I run the command directly - GOOGLE_APPLICATION_CREDENTIALS=emulator-creds.json firebase emulators:start --import=./data --export-on-exit=./data it exits fine. I haven't had much issue with it until yesterday.

It sounds like npm has an issue with this in general - https://stackoverflow.com/questions/54722158/node-and-npm-running-script-and-ctrl-c-triggers-sigint-twice, which means it's not specifically a firebase-cli issue, but if NPM doesn't fix it, not sure if there is a good way to mitigate the problem outside of switching off the npm script completely.

Thanks for looking into it. Filed a question over at NPM to see if it's something intended or a bug - npm/cli#1591

@samtstern
Copy link
Contributor

@kellyjandrews oh sorry I missed the part about it being part of npm start! Let us know what happens. Using the Firebase CLI within npm scripts is an important use case for us so if it can't be fixed on their side we can try to come up with a workaround here.

@kellyjandrews
Copy link
Author

@samtstern No problem - closed this for now as it seems like it's more of an NPM problem - but if not we can reopen. I'll keep you posted.

samtstern added a commit that referenced this issue Jul 31, 2020
@samtstern
Copy link
Contributor

@kellyjandrews I have a fix incoming for this issue.

This was referenced Aug 3, 2020
@kellyjandrews
Copy link
Author

@samtstern that's amazing - thanks so much!

@guillaumeprevost
Copy link

guillaumeprevost commented Jan 14, 2021

This seems to have been fixed in August 2020 with :
#2517
#2415

I don't know if there was some kind of regression recently, but I have just encountered the issue described in this original issue report.

In my case, adding --debug did not help.
I am using the current latest version of firebase-tools v9.2.0.

Here is how I am using it in NodeJS :

{
  ....
  "scripts": {
    "serve": "npm run build && firebase emulators:start --import=./emulators-data-import --export-on-exit=./emulators-data",
  ...

Should I post all the details as a comment in this issue or open a new issue ?

@samtstern
Copy link
Contributor

@guillaumeprevost yes please open a new issue with steps to reproduce! The simpler the better.

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

Successfully merging a pull request may close this issue.

3 participants