How to shutdown Firebase Emulator properly on Windows 10

Viewed 2696

When the firebase emulator:start is ran in my vscode powershell terminal, some java.exe windows pop open. Everything works great.

When I go to close the firebase emulator, using the ctrl+c command, there are logs in the terminal suggesting that everything is supposedly shutting down gracefully. Here's the log after ^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...
Terminate batch job (Y/N)? i  Found running emulator hub for project une-petite-partie at http://localhost:4400
i  Deleting directory C:\Users\schar\Documents\Programming\Projects\Card Game\data\firestore_export
i  Exporting data to: C:\Users\schar\Documents\Programming\Projects\Card Game\data
i  emulators: Received export request. Exporting data to C:\Users\schar\Documents\Programming\Projects\Card Game\data.
+  emulators: Export complete.
+  Export complete
i  emulators: Shutting down emulators.
i  ui: Stopping Emulator UI
!  Emulator UI has exited upon receiving signal: SIGINT
i  functions: Stopping Functions Emulator
i  hosting: Stopping Hosting Emulator
i  database: Stopping Database Emulator
!  Database Emulator has exited upon receiving signal: SIGINT
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT
i  pubsub: Stopping Pub/Sub Emulator
!  Pub/Sub Emulator has exited upon receiving signal: SIGINT
i  hub: Stopping emulator hub
i  logging: Stopping Logging Emulator

There's a (Y/N) prompt in there, so If I type Y or N, then the terminal comes back to regular powershell stand by.

In reality, the java.exe windows stays open. At that point, if I run firebase emulator:start again, I get an error saying that the emulator's ports are being used. If I close the java.exe windows manually and run the emulator again, it all works as expected.

I'm using Windows 10, powershell and VS code. I'm not looking for a hack to clear the ports as I can simply close the java.exe windows. I want to know how to close all of it in one fell swoop within powershell. Is there such a thing? Is this an issue I should be reporting?

3 Answers

I also had a similar issue. I had found two ways to solve this.

Method 1:

  1. Find the port and process ID using the following command

    netstat -a -o -n

  2. Use the below-mentioned command to kill that process

    taskkill /F /PID PROCESS_ID

where PROCESS_ID is the process id we got from step 1

  1. Start the emulator again

    firebase emulators:start

Method 2:

kill all of the Java process using the following command.

taskkill /f /im java.exe

This is how I do it.

  1. CTRL + C in the VSCode terminal.
  2. Manually close the Java Window
  3. Press the trashcan icon back in the VSCode terminal windows for the task.

From that state, I am able to start the Firebase Emulator task again just fine.

firebase emulators:start

Maybe there is a better way but after being baffled myself for ages I'm glad I found something that works at least. After you have done it a few times it gets quick enough to do it whenever you need to.

Hope that helps somebody. :)

That java.exe window is for Google Pub/Sub emulator which is using port 8085. Manually close this window to kill the process and close the port.

Another option is to specify a different port for Pub/Sub in firebase.json config file.

 {
    // ...
    "emulators": {
      "pubsub": {
        "host": "HOST",
        "port": "PORT"
      }
    }
  }
Related