[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime database emulator with node 18 stalled requests #2084

Closed
Hacksore opened this issue Feb 19, 2023 · 14 comments
Closed

Realtime database emulator with node 18 stalled requests #2084

Hacksore opened this issue Feb 19, 2023 · 14 comments

Comments

@Hacksore
Copy link
Hacksore commented Feb 19, 2023

[REQUIRED] Environment info

firebase-tools: 11.16.1

Platform: macOS/Linux

[REQUIRED] Test case

Below are the steps to repro this issue.

[REQUIRED] Steps to reproduce

node <= 16

  • Configure your system to use node 16.x
  • Pull this repo https://github.com/Hacksore/firebase-datatabase-node18
  • yarn to install dependancies
  • yarn start to run the test case
  • you should get an error but it shows at least the request resolves (not really that that's expected to me but that's not the problem this issue is highlighting)

node >= 18

[REQUIRED] Expected behavior

When using nodejs >=18 the emulator should work fine when setting FIREBASE_DATABASE_EMULATOR_HOST="localhost:9000"

[REQUIRED] Actual behavior

Stalled requests when using nodejs >= 18

@joehan joehan transferred this issue from firebase/firebase-tools Feb 21, 2023
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@maneesht
Copy link
Contributor

@Hacksore - do you have the emulator running on that port?

@Hacksore
Copy link
Author

@maneesht Yes the emulator is running on that port. Have you tried running the mcve in the issue body?

@maneesht
Copy link
Contributor
maneesht commented Feb 21, 2023

Yes. I was unable to reproduce the error. It logged { error: "can't find snapshot for userdata" }

@Hacksore
Copy link
Author

@maneesht Can you confirm if you had node >=18 sourced when you ran the test?

@maneesht
Copy link
Contributor

@Hacksore I'm on v18.11.0

@maneesht
Copy link
Contributor
maneesht commented Feb 21, 2023

Can you enable logging and provide the output from the logs below?
Example:

const db = admin.database();
admin.database.enableLogging(true);
...

@Hacksore
Copy link
Author
Hacksore commented Feb 21, 2023

@maneesht thanks for the pointer to enable debug mode. Here are the logs that seem to give more insight to the issue.

firebase-debug.log

[debug] [2023-02-21T23:00:31.490Z] ----------------------------------------------------------------------
[debug] [2023-02-21T23:00:31.491Z] Command:       /Users/hacksore/.nvm/versions/node/v18.11.0/bin/node /Users/hacksore/.yarn/bin/firebase emulators:start --import seed
[debug] [2023-02-21T23:00:31.491Z] CLI Version:   11.15.0
[debug] [2023-02-21T23:00:31.491Z] Platform:      darwin
[debug] [2023-02-21T23:00:31.492Z] Node Version:  v18.11.0
[debug] [2023-02-21T23:00:31.492Z] Time:          Tue Feb 21 2023 17:00:31 GMT-0600 (Central Standard Time)
[debug] [2023-02-21T23:00:31.492Z] ----------------------------------------------------------------------
[debug] 
[debug] [2023-02-21T23:00:31.524Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2023-02-21T23:00:31.524Z] > authorizing via signed-in user (redacted)
[debug] [2023-02-21T23:00:31.572Z] openjdk version "11.0.17" 2022-10-18

[debug] [2023-02-21T23:00:31.572Z] OpenJDK Runtime Environment Homebrew (build 11.0.17+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.17+0, mixed mode)

[debug] [2023-02-21T23:00:31.575Z] Parsed Java major version: 11
[info] i  emulators: Starting emulators: database {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: database"}}
[debug] [2023-02-21T23:00:32.096Z] [logging] Logging Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
[debug] [2023-02-21T23:00:32.097Z] [database] Database Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
[debug] [2023-02-21T23:00:32.097Z] assigned listening specs for emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400},{"address":"::1","family":"IPv6","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000},{"address":"::1","family":"IPv6","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"database":[{"address":"127.0.0.1","family":"IPv4","port":9000}]},"metadata":{"message":"assigned listening specs for emulators"}}
[debug] [2023-02-21T23:00:32.099Z] [hub] writing locator at /var/folders/1v/n6w12pg1455gyd172wxd9b2r0000gn/T/hub-test.json
[debug] [2023-02-21T23:00:32.102Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/test [none]
[debug] [2023-02-21T23:00:32.406Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/test 403
[debug] [2023-02-21T23:00:32.407Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/test {"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}}
[debug] [2023-02-21T23:00:32.407Z] HTTP Error: 403, The caller does not have permission
[debug] [2023-02-21T23:00:32.407Z] Failed to retrieve default database instance: {"name":"FirebaseError","children":[],"exit":2,"message":"Failed to get Firebase project test. Please make sure the project exists and your account has permission to access it.","original":{"name":"FirebaseError","children":[],"context":{"body":{"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}},"response":{"statusCode":403}},"exit":1,"message":"HTTP Error: 403, The caller does not have permission","status":403},"status":500} {"metadata":{"emulator":{"name":"database"},"message":"Failed to retrieve default database instance: {\"name\":\"FirebaseError\",\"children\":[],\"exit\":2,\"message\":\"Failed to get Firebase project test. Please make sure the project exists and your account has permission to access it.\",\"original\":{\"name\":\"FirebaseError\",\"children\":[],\"context\":{\"body\":{\"error\":{\"code\":403,\"message\":\"The caller does not have permission\",\"status\":\"PERMISSION_DENIED\"}},\"response\":{\"statusCode\":403}},\"exit\":1,\"message\":\"HTTP Error: 403, The caller does not have permission\",\"status\":403},\"status\":500}"}}
[debug] [2023-02-21T23:00:32.407Z] database rules config:  [{"instance":"test-default-rtdb","rules":"/Users/hacksore/Code/opensource/firebase-datatabase-node18/database.rules.json"}]
[debug] [2023-02-21T23:00:32.409Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"database"},"message":"Ignoring unsupported arg: projectId"}}
[debug] [2023-02-21T23:00:32.409Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"database"},"message":"Ignoring unsupported arg: auto_download"}}
[debug] [2023-02-21T23:00:32.409Z] Ignoring unsupported arg: rules {"metadata":{"emulator":{"name":"database"},"message":"Ignoring unsupported arg: rules"}}
[debug] [2023-02-21T23:00:32.409Z] Starting Database Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/Users/hacksore/.cache/firebase/emulators/firebase-database-emulator-v4.10.0.jar","--host","127.0.0.1","--port",9000,"--single_project_mode","Warning"],"optionalArgs":["port","host","functions_emulator_port","functions_emulator_host","single_project_mode"],"joinArgs":false} {"metadata":{"emulator":{"name":"database"},"message":"Starting Database Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/Users/hacksore/.cache/firebase/emulators/firebase-database-emulator-v4.10.0.jar\",\"--host\",\"127.0.0.1\",\"--port\",9000,\"--single_project_mode\",\"Warning\"],\"optionalArgs\":[\"port\",\"host\",\"functions_emulator_port\",\"functions_emulator_host\",\"single_project_mode\"],\"joinArgs\":false}"}}
[info] i  database: Database Emulator logging to database-debug.log {"metadata":{"emulator":{"name":"database"},"message":"Database Emulator logging to \u001b[1mdatabase-debug.log\u001b[22m"}}
[debug] [2023-02-21T23:00:32.763Z] WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/Users/hacksore/.cache/firebase/emulators/firebase-database-emulator-v4.10.0.jar) to field sun.nio.ch.SelectorImpl.selectedKeys
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
 {"metadata":{"emulator":{"name":"database"},"message":"WARNING: An illegal reflective access operation has occurred\nWARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/Users/hacksore/.cache/firebase/emulators/firebase-database-emulator-v4.10.0.jar) to field sun.nio.ch.SelectorImpl.selectedKeys\nWARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil\nWARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations\nWARNING: All illegal access operations will be denied in a future release\n"}}
[debug] [2023-02-21T23:00:33.104Z] 17:00:33.103 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
 {"metadata":{"emulator":{"name":"database"},"message":"17:00:33.103 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started\n"}}
[debug] [2023-02-21T23:00:33.184Z] 17:00:33.184 [main] INFO com.firebase.server.forge.App$ - Listening at 127.0.0.1:9000
 {"metadata":{"emulator":{"name":"database"},"message":"17:00:33.184 [main] INFO com.firebase.server.forge.App$ - Listening at 127.0.0.1:9000\n"}}
[info] i  database: Importing data from /Users/hacksore/Code/opensource/firebase-datatabase-node18/seed/database_export/test.json {"metadata":{"emulator":{"name":"database"},"message":"Importing data from /Users/hacksore/Code/opensource/firebase-datatabase-node18/seed/database_export/test.json"}}
[debug] [2023-02-21T23:00:33.604Z] 17:00:33.604 [NamespaceSystem-akka.actor.default-dispatcher-5] INFO com.firebase.core.namespace.NamespaceActor - test successfully activated FBKV (SurveyIdle(0)) wait: 76ms, init: 0ms
 {"metadata":{"emulator":{"name":"database"},"message":"17:00:33.604 [NamespaceSystem-akka.actor.default-dispatcher-5] INFO com.firebase.core.namespace.NamespaceActor - test successfully activated FBKV (SurveyIdle(0)) wait: 76ms, init: 0ms\n"}}
[debug] [2023-02-21T23:00:33.658Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[debug] [2023-02-21T23:00:33.658Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[debug] [2023-02-21T23:00:33.658Z] Starting Emulator UI with command {"binary":"node","args":["/Users/hacksore/.cache/firebase/emulators/ui-v1.11.1/server/server.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\"binary\":\"node\",\"args\":[\"/Users/hacksore/.cache/firebase/emulators/ui-v1.11.1/server/server.js\"],\"optionalArgs\":[],\"joinArgs\":false}"}}
[info] i  ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[debug] [2023-02-21T23:00:33.724Z] Web / API server started at 127.0.0.1:4000
 {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at 127.0.0.1:4000\n"}}
[debug] [2023-02-21T23:00:33.724Z] Web / API server started at ::1:4000
 {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at ::1:4000\n"}}
[debug] [2023-02-21T23:00:33.916Z] >>> [apiv2][query] PUT http://127.0.0.1:9000/.settings/rules.json ns=test-default-rtdb
[debug] [2023-02-21T23:00:33.916Z] >>> [apiv2][body] PUT http://127.0.0.1:9000/.settings/rules.json "{\n  \"rules\": {\n    \"userdata\": {\n      \".read\": true,\n      \".write\": false\n    }\n  }\n}"
[debug] [2023-02-21T23:00:33.922Z] 17:00:33.922 [FirebaseWorkerPool-1-3] WARN com.firebase.core.persistence.backend.dummy.EmulatorMetadataPersistence - Multiple projectIds are not recommended in single project mode. Requested 
namespace test-default-rtdb, but the emulator is configured for test. To 
opt-out of single project mode add/set the single_project_mode: false property in 
the firebase.json emulators config. 
 {"metadata":{"emulator":{"name":"database"},"message":"17:00:33.922 [FirebaseWorkerPool-1-3] WARN com.firebase.core.persistence.backend.dummy.EmulatorMetadataPersistence - Multiple projectIds are not recommended in single project mode. Requested \nnamespace test-default-rtdb, but the emulator is configured for test. To \nopt-out of single project mode add/set the single_project_mode: false property in \nthe firebase.json emulators config. \n"}}
[debug] [2023-02-21T23:00:33.926Z] 17:00:33.926 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO com.firebase.core.namespace.NamespaceActor - test-default-rtdb successfully activated FBKV (SurveyIdle(0)) wait: 1ms, init: 0ms
 {"metadata":{"emulator":{"name":"database"},"message":"17:00:33.926 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO com.firebase.core.namespace.NamespaceActor - test-default-rtdb successfully activated FBKV (SurveyIdle(0)) wait: 1ms, init: 0ms\n"}}
[debug] [2023-02-21T23:00:33.942Z] 17:00:33.942 [NamespaceSystem-blocking-namespace-operation-dispatcher-7] INFO com.firebase.core.namespace.StateManager - Namespace test-default-rtdb status Active to Active
 {"metadata":{"emulator":{"name":"database"},"message":"17:00:33.942 [NamespaceSystem-blocking-namespace-operation-dispatcher-7] INFO com.firebase.core.namespace.StateManager - Namespace test-default-rtdb status Active to Active\n"}}
[debug] [2023-02-21T23:00:33.955Z] <<< [apiv2][status] PUT http://127.0.0.1:9000/.settings/rules.json 200
[debug] [2023-02-21T23:00:33.955Z] <<< [apiv2][body] PUT http://127.0.0.1:9000/.settings/rules.json {"status":"ok"}
[info] 
┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000/               │
└─────────────────────────────────────────────────────────────┘

┌──────────┬────────────────┬────────────────────────────────┐
│ Emulator │ Host:Port      │ View in Emulator UI            │
├──────────┼────────────────┼────────────────────────────────┤
│ Database │ 127.0.0.1:9000 │ http://127.0.0.1:4000/database │
└──────────┴────────────────┴────────────────────────────────┘
  Emulator Hub running at 127.0.0.1:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
 

And I see the client repeatedly printing this.
Console output:

 node --loader ts-node/esm index.ts
[bug] (node:56371) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
[bug] (Use `node --trace-warnings ...` to show where the warning was created)
[emulator] i  emulators: Starting emulators: database
[bug] FIREBASE_DATABASE_EMULATOR_HOST: localhost:9000
[bug] firebase initializeApp...
[bug] initialized firebase server app!
[bug] [2023-02-21T23:00:31.701Z]  @firebase/database: p:0: Browser went online. 
[bug] [2023-02-21T23:00:31.701Z]  @firebase/database: p:0: Auth token refreshed 
[bug] [2023-02-21T23:00:31.704Z]  @firebase/database: p:0: Making a connection attempt 
[bug] [2023-02-21T23:00:31.705Z]  @firebase/database: getToken() completed. Creating connection. 
[bug] [2023-02-21T23:00:31.705Z]  @firebase/database: c:0:0: Connection created 
[bug] [2023-02-21T23:00:31.707Z]  @firebase/database: c:0:0:0 Websocket connecting to ws://localhost:9000/.ws?v=5&ns= 
[bug] [2023-02-21T23:00:31.715Z]  @firebase/database: c:0:0:0 WebSocket error.  Closing connection. 
[bug] [2023-02-21T23:00:31.715Z]  @firebase/database: c:0:0:0 Network error: ws://localhost:9000/.ws?v=5&ns=: connect ECONNREFUSED ::1:9000 
[bug] [2023-02-21T23:00:31.715Z]  @firebase/database: c:0:0:0 WebSocket is closing itself 
[bug] [2023-02-21T23:00:31.715Z]  @firebase/database: c:0:0:0 Websocket connection was disconnected. 
[bug] [2023-02-21T23:00:31.715Z]  @firebase/database: c:0:0: Realtime connection failed. 
[bug] [2023-02-21T23:00:31.716Z]  @firebase/database: c:0:0: Closing realtime connection. 
[bug] [2023-02-21T23:00:31.716Z]  @firebase/database: c:0:0: Shutting down all connections 
[bug] [2023-02-21T23:00:31.716Z]  @firebase/database: p:0: data client disconnected 
[bug] [2023-02-21T23:00:31.716Z]  @firebase/database: p:0: Trying to reconnect in 142.77514556858725ms 
[bug] [2023-02-21T23:00:31.716Z]  @firebase/database: 0: onDisconnectEvents 
[bug] [2023-02-21T23:00:31.858Z]  @firebase/database: p:0: Making a connection attempt 
[bug] [2023-02-21T23:00:31.860Z]  @firebase/database: getToken() completed. Creating connection. 
[bug] [2023-02-21T23:00:31.860Z]  @firebase/database: c:0:1: Connection created 
[bug] [2023-02-21T23:00:31.861Z]  @firebase/database: c:0:1:0 Websocket connecting to ws://localhost:9000/.ws?v=5&ns= 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1:0 WebSocket error.  Closing connection. 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1:0 Network error: ws://localhost:9000/.ws?v=5&ns=: connect ECONNREFUSED ::1:9000 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1:0 WebSocket is closing itself 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1:0 Websocket connection was disconnected. 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1: Realtime connection failed. 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1: Closing realtime connection. 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: c:0:1: Shutting down all connections 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: p:0: data client disconnected 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: p:0: Trying to reconnect in 33.68043411452045ms 
[bug] [2023-02-21T23:00:31.862Z]  @firebase/database: 0: onDisconnectEvents 
[bug] [2023-02-21T23:00:31.897Z]  @firebase/database: p:0: Making a connection attempt 
[bug] [2023-02-21T23:00:31.898Z]  @firebase/database: getToken() completed. Creating connection. 
[bug] [2023-02-21T23:00:31.898Z]  @firebase/database: c:0:2: Connection created 
[bug] [2023-02-21T23:00:31.899Z]  @firebase/database: c:0:2:0 Websocket connecting to ws://localhost:9000/.ws?v=5&ns= 
[bug] [2023-02-21T23:00:31.901Z]  @firebase/database: c:0:2:0 WebSocket error.  Closing connection. 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: c:0:2:0 Network error: ws://localhost:9000/.ws?v=5&ns=: connect ECONNREFUSED ::1:9000 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: c:0:2:0 WebSocket is closing itself 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: c:0:2:0 Websocket connection was disconnected. 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: c:0:2: Realtime connection failed. 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: c:0:2: Closing realtime connection. 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: c:0:2: Shutting down all connections 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: p:0: data client disconnected 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: p:0: Trying to reconnect in 758.011513475497ms 
[bug] [2023-02-21T23:00:31.902Z]  @firebase/database: 0: onDisconnectEvents 
[emulator] i  database: Database Emulator logging to database-debug.log
[bug] [2023-02-21T23:00:32.661Z]  @firebase/database: p:0: Making a connection attempt 
[bug] [2023-02-21T23:00:32.662Z]  @firebase/database: getToken() completed. Creating connection. 
[bug] [2023-02-21T23:00:32.662Z]  @firebase/database: c:0:3: Connection created 
[bug] [2023-02-21T23:00:32.664Z]  @firebase/database: c:0:3:0 Websocket connecting to ws://localhost:9000/.ws?v=5&ns= 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3:0 WebSocket error.  Closing connection. 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3:0 Network error: ws://localhost:9000/.ws?v=5&ns=: connect ECONNREFUSED ::1:9000 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3:0 WebSocket is closing itself 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3:0 Websocket connection was disconnected. 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3: Realtime connection failed. 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3: Closing realtime connection. 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: c:0:3: Shutting down all connections 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: p:0: data client disconnected 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: p:0: Trying to reconnect in 824.4389802094277ms 
[bug] [2023-02-21T23:00:32.665Z]  @firebase/database: 0: onDisconnectEvents 
[emulator] i  database: Importing data from /Users/hacksore/Code/opensource/firebase-datatabase-node18/seed/database_export/test.json
[bug] [2023-02-21T23:00:33.490Z]  @firebase/database: p:0: Making a connection attempt 
[bug] [2023-02-21T23:00:33.492Z]  @firebase/database: getToken() completed. Creating connection. 
[bug] [2023-02-21T23:00:33.492Z]  @firebase/database: c:0:4: Connection created 
[bug] [2023-02-21T23:00:33.493Z]  @firebase/database: c:0:4:0 Websocket connecting to ws://localhost:9000/.ws?v=5&ns= 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4:0 WebSocket error.  Closing connection. 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4:0 Network error: ws://localhost:9000/.ws?v=5&ns=: connect ECONNREFUSED ::1:9000 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4:0 WebSocket is closing itself 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4:0 Websocket connection was disconnected. 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4: Realtime connection failed. 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4: Closing realtime connection. 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: c:0:4: Shutting down all connections 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: p:0: data client disconnected 
[bug] [2023-02-21T23:00:33.494Z]  @firebase/database: p:0: Trying to reconnect in 1143.0725072118735ms 
[bug] [2023-02-21T23:00:33.495Z]  @firebase/database: 0: onDisconnectEvents 

@lahirumaramba
Copy link
Member
lahirumaramba commented Feb 23, 2023

@Hacksore long shot and I didn't test this, but can you try adding the host as localhost in your firebase.json and see if that helps?

"database": {
      "port": 9000,
      "host": "localhost"
}

This is based on a guess because your emulators are running on 127.0.0.1 but the rtdb requests are pointing to localhost, (which technically shouldn't break things, but just in case).

@Hacksore
Copy link
Author
Hacksore commented Feb 24, 2023

@lahirumaramba I think you've found the issue, good catch!

If I change the env var to FIREBASE_DATABASE_EMULATOR_HOST="127.0.0.1:9000" no more stalled requests on node 18 for me.

However, it doesn't work to set host to localhost in the firebase.json for the database and keep the env var host as localhost:9000.

Has something changed recently that could potentially cause this?

@lahirumaramba
Copy link
Member

Glad you got it fixed! Using the IP address 127.0.0.1 is more reliable than using localhost as localhost might not resolve correctly on IPv6.

@Hacksore
Copy link
Author

@lahirumaramba would it make sense to update the docs to reflect the usage of 127.0.0.1 over localhost?

https://firebase.google.com/docs/emulator-suite/connect_rtdb#admin_sdks

@lahirumaramba
Copy link
Member

Hi @Hacksore, That might not be a bad idea! There is a similar PR to update a codelab here firebase/emulators-codelab#22

@christhompsongoogle @yuchenshi @egilmorez WDYT? Should we update the docs to use 127.0.0.1?

@lahirumaramba lahirumaramba self-assigned this Mar 20, 2023
@christhompsongoogle
Copy link

Yes I think so too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants