firebase / firebase-tools-ui

A local-first UI for Firebase Emulator Suite.
https://firebase.googleblog.com/2020/05/local-firebase-emulator-ui.html
Apache License 2.0
261 stars 60 forks source link

Did not find any running emulators for project... #1018

Open stemarco opened 4 months ago

stemarco commented 4 months ago

Describe the bug The emulator export script will on occassion not find a running emulator even though the emulator is still running.

This error seems to correlate to periodic update checks

To Reproduce

  1. Run the emulator
  2. Run a script that periodically calls firebase emulators:export --force ./forced-backup
  3. Wait

Expected behavior The script should print the following each time it runs:

i  Found running emulator hub for project PROJECT_NAME at http://127.0.0.1:4400
i  Exporting data to: PATH/forced-backup
✔  Export complete

Screenshots 1)

...multiple save messages
 ╭───────────────────────────────────────────────────────────────────╮
   │                                                                   │
   │                 Update available 13.0.2 → 13.1.0                  │
   │          To update to the latest version using npm, run           │
   │                   npm install -g firebase-tools                   │
   │   For other CLI management options, visit the CLI documentation   │
   │                                                                   │
   │                                                                   │
   │                                                                   │
   ╰───────────────────────────────────────────────────────────────────╯

Error: Did not find any running emulators for project PROJECT_NAME.

2) after update

...multiple save messages

Error: Did not find any running emulators for project grazeful-demo.

╭───────────────────────────────────────────────────────────────────╮
   │                                                                   │
   │                 Update available 13.1.0 → 13.3.1                  │
   │          To update to the latest version using npm, run           │
   │                   npm install -g firebase-tools                   │
   │   For other CLI management options, visit the CLI documentation   │
   │                                                                   │
   │                                                                   │
   │                                                                   │
   ╰───────────────────────────────────────────────────────────────────╯

Error: Did not find any running emulators for project PROJECT_NAME.

Desktop (please complete the following information): Ventura 13.6 uname -a: Darwin stp.local 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000 arm64

Example Save Script (MacOS):

#!/bin/sh

while :
do
    firebase emulators:export --force ./emulator-backup
    if [ $? -eq 0 ]; then
        echo "saved"
    else
        osascript -e 'display notification "Save Failed" with title "Failed"'
    fi  

    sleep 3600
done
stemarco commented 4 months ago

I've started reading the emulator code hoping to find a signal that could bring export back to life. If I follow correctly, the update message is emitted only on process.exit, but the emulator is still running. It seems the file hub-PROJECT-NAME.json in os.tmpdir() is getting deleted on this signal. Copying a new json file with the content {"version":"13.1.0","origins":["http://127.0.0.1:4400","http://[::1]:4400"]} restores exports. This json was copied fom an instance running emulator v12.3.1, but localhost:4400 has the following slightly different json:

{
  "version": "13.1.0",
  "origins": [
    "http://127.0.0.1:4400",
    "http://[::1]:4400"
  ],
  "host": "127.0.0.1",
  "port": 4400
}

Untested, but I think this should work to restore the hub file of a running emulator: wget -O $(node -e "console.log(os.tmpdir())")/hub-PROJECT-NAME.json http://localhost:4400/

stemarco commented 4 months ago

Just noticed this issue was filed under firebase-tools-ui instead of firebase-tools. Can it be moved?