firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 932 forks source link

starting emulators opens a java window that isn't directly controlled by emulators #3871

Open markgoho opened 2 years ago

markgoho commented 2 years ago

[REQUIRED] Environment info

firebase-tools: 9.21.0

java 17.0.1 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

Platform: Windows 11

[REQUIRED] Test case

want to start emulators

[REQUIRED] Steps to reproduce

start emulators see java window open stop emulators see java window remain open re-start emulators see error about ports in use

[REQUIRED] Expected behavior

emulators can be run without spawning java window

[REQUIRED] Actual behavior

emulators run and spawn java window but don't have control over the process

Video showing behavior: https://www.loom.com/share/bc86030a8e224f70a740e4e0d89d5598

DKorosec commented 2 years ago

I've had the exact same issue, but on Windows 10 and firebase-tools: 10.1.0 "Fixed" the issue by switching to OpenJDK @ https://adoptium.net/?variant=openjdk8 Quite annoying, as if the window was not closed the emulator could not start, because ports were in use, and also broke precommit hooks (running emulator in one of the steps caused everything to hung).

blikblum commented 2 years ago

"Fixed" the issue by switching to OpenJDK @ https://adoptium.net/?variant=openjdk8

This is not an option going forward given that next firebase-tools versions will require java 11 or superior

I've had the exact same issue, but on Windows 10 and firebase-tools: 10.1.0

Same here with windows 10, java 17 and firebase tools 10.6.0

The windows is from firestore and has the following output


Apr 10, 2022 8:14:38 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://localhost:56350
API endpoint: http://localhost:8082
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8082

Dev App Server is now running.
DKorosec commented 2 years ago

"Fixed" the issue by switching to OpenJDK @ https://adoptium.net/?variant=openjdk8

This is not an option going forward given that next firebase-tools versions will require java 11 or superior

I've had the exact same issue, but on Windows 10 and firebase-tools: 10.1.0

Same here with windows 10, java 17 and firebase tools 10.6.0

The windows is from firestore and has the following output


Apr 10, 2022 8:14:38 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://localhost:56350
API endpoint: http://localhost:8082
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8082

Dev App Server is now running.

Then go for Open JDK 17, I'm using it and it works fine (https://adoptium.net/?variant=openjdk17).

Corchoneitor commented 2 years ago

Also happens with firebase-tools 10.1.5 and jdk-18.

In my case, there are 2 unwanted java windows:

Really annoying.

lisajian commented 2 years ago

Seems like this is an issue specific to Java 17 and Windows users; if someone in the open source community has more context on this, we'd happily accept/review any PRs

Psycarlo commented 1 year ago

Why was this closed? I still have this issue

Windows: Windows 10 Pro Firebase Tools: v11.15.0

I fixed by installing: https://adoptium.net/temurin/releases/?version=17 And restarting my machine

markgoho commented 1 year ago

hey @Psycarlo I don't think the issue was closed -- and I'm still experiencing it too!

it looks like (per this comment) the OpenJDK version doesn't do this.

ishowta commented 1 year ago

This is a hack, but I was able to get it to exit by setting detached to false. I don't know about export-on-exit as I haven't used it.

https://github.com/firebase/firebase-tools/blob/master/src/emulator/downloadableEmulators.ts#L365-L369

Wadeck commented 1 year ago

Just to add some data points.

After rollback, everything is fine again.

(Windows 10 + Oracle JDKs, tested with both firebase 10.6.0 and 11.19.0)

Also, in terms of export-on-exit behavior. Closing the popup prevents the export on exit to happen. Detached=false will lead to an error during export, preventing it as well.

christhompsongoogle commented 1 year ago

I did some investigation and this seems to be caused by a bug in node's child_process.spawn function:

https://github.com/nodejs/node/issues/21825

If anyone is interested in trying their hand at a fix, here's the relevant location in firebase-tools below. The code will probably need to be moved off of child_process.spawn and on to something else (or somehow make the child processes resistant to SIGINT before export.)

https://cs.opensource.google/firebase-sdk/firebase-tools/+/master:src/emulator/downloadableEmulators.ts;drc=f200dcb4865763a05c0426f4c3ec9640c9c4ff7f;l=369

A proper fix ideally would shut down the entire suite on SIGINT in the main window and needs to preserve export behavior.

akettmann-id commented 1 month ago

Currently facing the same struggle here, we have Python code that uses Firebase. Unit tests need a firebase emulator, but if I send the main process a SIGINT, it dies immediately and leaves its child processes (the actual emulators) behind and running.

Reproducible with the following:


import subprocess
import signal
import shutil
import time

FIREBASE = shutil.which('firebase')

# Process starts here
proc = subprocess.Popen([FIREBASE, 'emulators:start'])
time.sleep(30)
proc.send_signal(signal.SIGINT)
# Python checks the subprocess and updates the returncode
proc.poll()
assert proc.returncode == -2

will leave any emulators you may have started up and running. I can't find any signal I can send the process to get it to shut down cleanly. Going to do something dumb with firebase emulators:exec running some Python code that will shut down once I ask it to instead. Making my entrypoint for ALL of my tests be the firebase emulator doesn't work for me.