firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

firebase emulators:exec fails to kill the firestore emulator

Open compojoom opened this issue 7 years ago • 15 comments

I've been trying to run our tests on circleci and managed to get them top run, but circleci keeps reporting them as failing, despite them succeeding.

The problem is that the step that runs our tests: ./node_modules/.bin/firebase emulators:exec "yarn --ignore-engines test_ci"

exits with: "Error: firestore: firestore: Unable to terminate emulator process (PID=200)"

I've executed the above command on 2 different mac machines and it fails on them as well.

the emulator is acutually killed few seconds after the error is displayed. I guess that this is a timing issue?

we use firebase-tools 6.10.0 and @firebase/testing 0.10.0

compojoom avatar Jun 04 '19 15:06 compojoom

@compojoom I have seen this issue too but not reliably, I am going to move this over to firebase-tools.

samtstern avatar Jun 04 '19 15:06 samtstern

well, for me it happens in 99% of the cases. I've seen it complete without error, but unfortunately most of the time it spills out that error.

compojoom avatar Jun 04 '19 15:06 compojoom

@compojoom yeah I used to be able to get this reliably on one of my machines, but now I can't get it to happen anywhere!

Some questions:

  • What emulators are started (you can tell by reading the logs)? Is it just Firestore or are others started as well?
  • If you run firebase emulators:start and then wait for them all to start and then kill the process using Ctrl+C do you see the same error?

samtstern avatar Jun 04 '19 16:06 samtstern

ctrl+c kills the emulators. The problem is that on CI server I can't start the emulators and then run to the next step. I have to use emulators:exec - and this is where it fails.

The functions and firestore emulator are running:

✔  functions: Emulator started at http://localhost:5001
i  firestore: Logging to firestore-debug.log
✔  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIREBASE_FIRESTORE_EMULATOR_ADDRESS=localhost:8080

and then after mocha --exit I get:

✔  Script exited successfully (code 0)
i  Shutting down emulators.
i  Stopping functions emulator
i  Stopping firestore emulator

Error: firestore: firestore: Unable to terminate emulator process (PID=200)
Exited with code 1

compojoom avatar Jun 04 '19 20:06 compojoom

just for info - tested it with 6.11 and the same problem persist.

compojoom avatar Jun 05 '19 07:06 compojoom

Huh, this is so strange, @samstern, can't we just send all child processes a hard kill command when we're ready to finish?

abeisgoat avatar Jun 06 '19 17:06 abeisgoat

@compojoom I haven't seen this in a long time (I used to see it occasionally). Do you still see it?

samtstern avatar Jul 11 '19 17:07 samtstern

Hey @compojoom. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jul 19 '19 01:07 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@compojoom if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Jul 23 '19 01:07 google-oss-bot

Whenever firebase functions throwns an unhandled error w/c closes the emulator, the process is not cleanup up.

by default, it uses port 8080, so checked that the java process is not yet closed. So basically just stop the process using pkill java

and restart the emulator

chan-dev avatar Nov 21 '19 13:11 chan-dev

Similar issue:

I Found jest wasn't exiting during the firebase emulators:exec command. Appending the following options helped it exit and the emulator to terminate:

firebase emulators:exec "jest --forceExit --detectOpenHandles"

More info here: https://jestjs.io/docs/en/cli.html#--forceexit

benwinding avatar Apr 19 '20 12:04 benwinding

I have the same problem with jest but the only emulator I have a problem with is the pubsub one. Even with the options from @benwinding . If I run twice my tests, it appear to have a emulator error telling me that port is already taken. If I look to windows process manager, I have a java process to kill if I want to make it work again.

I'm on windows 10 and firebase-tools 8.1.1

clementAC avatar Apr 20 '20 07:04 clementAC

I have the same problem with jest but the only emulator I have a problem with is the pubsub one. Even with the options from @benwinding . If I run twice my tests, it appear to have a emulator error telling me that port is already taken. If I look to windows process manager, I have a java process to kill if I want to make it work again.

I'm on windows 10 and firebase-tools 8.1.1

I was able to go around this issue by doing the following:

  1. run the following from the command line netstat -a -o -n this will list the processes, find out which one is using port 8085 or whatever port you configured for pubsub

  2. run the following from the command line to kill that process. taskkill /F /PID 2940

2940 is the process ID identified above

  1. Start the emulator(s) again firebase emulators:start.

Regards,

mesmin avatar Aug 01 '20 00:08 mesmin

I have the same problem with jest but the only emulator I have a problem with is the pubsub one. Even with the options from @benwinding . If I run twice my tests, it appear to have a emulator error telling me that port is already taken. If I look to windows process manager, I have a java process to kill if I want to make it work again.

I'm on windows 10 and firebase-tools 8.1.1

Yes, this works! Also had a problem with Pub/sub port i.e. "could not start pub/sub emulator, port taken." after killing emulator with Ctrl+c. To solve the problem just open Windows task manager and select the java process and "end task"

ReaperTech avatar May 24 '21 13:05 ReaperTech

Similar issue:

I Found jest wasn't exiting during the firebase emulators:exec command. Appending the following options helped it exit and the emulator to terminate:

firebase emulators:exec "jest --forceExit --detectOpenHandles"

More info here: https://jestjs.io/docs/en/cli.html#--forceexit

I'm having the same problem @benwinding! I tried appending the flags you mentioned helping you but emulators exec still seems to be stuck within the github ci. I'm not sure if this is because of emulators:exec or jest. I've also appended the --watchAll=false flag just in case that was causing problems 😓.

EDIT: Never mind turns out I was calling the script with watchmode turned on inside my workflow, the flags work thank you!

joshpetit avatar Sep 19 '21 14:09 joshpetit