'Firebase database emulator not starting (other emulators are working)

I'm trying to get the database emulator working.

Running firebase emulators:start --only auth,hosting works fine an give the following output:

i  emulators: Starting emulators: auth, hosting
i  hosting: Serving hosting files from: dist/spa
✔  hosting: Local server: http://localhost:5000
i  ui: Emulator UI logging to ui-debug.log

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

┌────────────────┬────────────────┬────────────────────────────┐
│ Emulator       │ Host:Port      │ View in Emulator UI        │
├────────────────┼────────────────┼────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth │
├────────────────┼────────────────┼────────────────────────────┤
│ Hosting        │ localhost:5000 │ n/a                        │
└────────────────┴────────────────┴────────────────────────────┘
  Emulator Hub running at localhost:4400
  Other reserved ports: 4500

However, as soon as I include emulation of the database the only thing I get is:

i  emulators: Starting emulators: auth, database, hosting
i  database: Database Emulator logging to database-debug.log
i  emulators: Shutting down emulators.
i  database: Stopping Database Emulator
i  hub: Stopping emulator hub

Error: TIMEOUT: Port 9000 on localhost was not active within 60000ms

Going to http://localhost:9000 does give a response from the database so it seems to be running. But it hangs and does not allow the other emulators or the UI to start and will eventually time out.

This is the contents of the database-debug.log

08:23:16.050 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
08:23:16.247 [main] INFO com.firebase.server.forge.App$ - Listening at localhost:9000
08:24:14.144 [Thread-0] INFO com.firebase.server.forge.App$ - Attempting graceful shutdown.
08:24:14.156 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO com.firebase.core.namespace.Terminator$Terminator - 1 actors left to terminate: fake-server
08:24:14.163 [NamespaceSystem-akka.actor.default-dispatcher-5] INFO com.firebase.core.namespace.NamespaceActor - Stopping namespace actor for fake-server
08:24:14.164 [NamespaceSystem-akka.actor.default-dispatcher-5] INFO com.firebase.core.namespace.NamespaceActor - Gauges removed for fake-server
08:24:14.170 [Thread-0] INFO com.firebase.server.forge.App$ - Graceful shutdown complete.

Update

I have:

  • created a new project using firebase init just to try the emulator and I get the same behaviour.
  • configured the database emulator to run on a different port. No avail.
  • upgraded java to openjdk version 18... (initially I had a very old version of java on my mac)


Solution 1:[1]

While running firebase emulators:start you might get an output similar to this one ?

i  emulators: Starting emulators: database, hosting
i  database: Database Emulator logging to database-debug.log
i  emulators: Shutting down emulators.
i  database: Stopping Database Emulator.
i  hub: Stopping emulator hub

Error: TIMEOUT: Port 9000 on localhost was not active within 60000ms ?

Steps to fix the error ?

  1. Just go through Latest versions of Java, download it from Oracle. ??
  2. Add the "host": "127.0.0.1" entry to the firebase.json file as shown below in the emulators section. ?
  3. Copy the given code and add to emulators section. ?
  "emulators": {
    "database": {
      "port": 9000,
      "host": "127.0.0.1"
    },  
  1. Run firebase emulators:start again! ??

  2. Happy Coding ????

  3. Click here to view the Final Out! ?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1