Firebase-tools: firestore emulator on wsl2 does not work, results in ERR_CONNECTION_REFUSED

Created on 5 Jun 2020  ยท  16Comments  ยท  Source: firebase/firebase-tools

[REQUIRED] Environment info

firebase-tools:8.4.1

Platform: wsl2 with Ubuntu-18.04

[REQUIRED] Test case


Start emulator firebase emulators:start --only firestore
Navigate to http://127.0.0.1:4000/firestore
Try to write in the database or simply check console

[REQUIRED] Steps to reproduce


Brand new project firebase init
Select emulators and firestore
firebase init to get firestore files firestore.rules firestore.indexes.json
Follow test case above - go to url and write to database

[REQUIRED] Expected behavior


Should be able to write and read collection through emulator UI

[REQUIRED] Actual behavior

No changes are made to firestore, and receive error in console

xhrio.js:622 POST http://localhost:8080/google.firestore.v1.Firestore/Write/channel?database=projects%2Fmyproj%2Fdatabases%2F(default)&VER=8&RID=78563&CVER=22&X-HTTP-Session-Id=gsessionid&%24httpHeaders=Authorization%3ABearer%20owner%0D%0AX-Goog-Api-Client%3Agl-js%2F%20fire%2F7.14.3%0D%0A&zx=u51ejgj9v8vq&t=1 net::ERR_CONNECTION_REFUSED
firebase emulators:start --only firestore --debug
[2020-06-05T19:52:33.335Z] > 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"]
[2020-06-05T19:52:33.336Z] > authorizing via signed-in user
i  emulators: Starting emulators: firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: firestore"}}
[2020-06-05T19:52:33.350Z] [hub] writing locator at /tmp/hub-leotestproj2.json
[2020-06-05T19:52:33.372Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: projectId"}}
[2020-06-05T19:52:33.372Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-05T19:52:33.372Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/home/leo/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar","--host","localhost","--port",8080,"--rules","/home/leo/projects/practice/firebase-proj/firestore.rules"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/home/leo/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar\",\"--host\",\"localhost\",\"--port\",8080,\"--rules\",\"/home/leo/projects/practice/firebase-proj/firestore.rules\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"functions_emulator\",\"seed_from_export\"],\"joinArgs\":false}"}}
i  firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[2020-06-05T19:52:33.966Z] API endpoint: http://localhost:8080 {"metadata":{"emulator":{"name":"firestore"},"message":"API endpoint: http://localhost:8080"}}
[2020-06-05T19:52:33.966Z] 
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8080

Dev App Server is now running.

 {"metadata":{"emulator":{"name":"firestore"},"message":"\nIf you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\n\n   export FIRESTORE_EMULATOR_HOST=localhost:8080\n\nDev App Server is now running.\n\n"}}
[2020-06-05T19:52:34.138Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-05T19:52:34.138Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[2020-06-05T19:52:34.138Z] Starting Emulator UI with command {"binary":"node","args":["/home/leo/.cache/firebase/emulators/ui-v1.0.0/server.bundle.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\"binary\":\"node\",\"args\":[\"/home/leo/.cache/firebase/emulators/ui-v1.0.0/server.bundle.js\"],\"optionalArgs\":[],\"joinArgs\":false}"}}
i  ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[2020-06-05T19:52:34.254Z] Web / API server started at http://localhost:4000
 {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at http://localhost:4000\n"}}

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โœ”  All emulators ready! View status and logs at http://localhost:4000 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Emulator  โ”‚ Host:Port      โ”‚ View in Emulator UI             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Firestore โ”‚ localhost:8080 โ”‚ http://localhost:4000/firestore โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  Other reserved ports: 4400, 4500

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

Note: I tried this on mac and it worked fine

emulator-suite firestore ui

Most helpful comment

I see two issues here:

  1. Firestore emulator does not respond to 127.0.0.1 when asked to listen on localhost / 127.0.0.1 on WSL.

    • This may be an issue with WSL and much harder to troubleshoot.

  2. Emulator UI tries to construct an invalid URL like http://0.0.0.0:8080 when Firestore emulator is configured to listen on 0.0.0.0.

Hopefully fixing 2. can give you a reasonable workaround, and we'd appreciate any help on root-causing or working around 1.

All 16 comments

I see you're using 127.0.0.1 ... is it the same if you use localhost?

@samtstern thanks for the reply, using http://localhost:4000/firestore results in the same ERR_CONNECTION_REFUSED error

Might be relevant, I can access my app through localhost and my inet address through ifconfig
but I can only access the firestore through localhost not my inet address
i.e. app is accessible at http://localhost:3000 and http://172.29.180.12:3000
but emulator UI is only accessible at http://localhost:4000/ not http://172.29.180.12:4000

This one has stumped me. It seems like the error is occurring when the UI running on localhost:4000 attempts to make a POST request to the Firestore emulator running at localhost:8080 ... maybe @yuchenshi or @abeisgoat has an idea.

but I can only access the firestore through localhost not my inet address
but emulator UI is only accessible at http://localhost:4000/ not http://172.29.180.12:4000

Emulators only listen to localhost by default. If you'd rather want them to listen on all IP addresses, please set host to 0.0.0.0 for both Firestore and Emulator UI in firebase.json. Example:

{
  // ...
  "emulators": {
    "firestore": {"host": "0.0.0.0", "port": 8080},
    "ui": {"host": "0.0.0.0", "port": 4000}
  }
}

And please let me know if visiting the Emulator UI through inet address works for you. If not, try also directly setting host to the inet address like "firestore": {"host": "172.29.180.12", "port": 8080},.

We have to admit that wsl2 is new territory to most of us here and we're also learning with you, so we really appreciate your help.

Thanks @yuchenshi , setting the host to 0.0.0.0 worked to be able to visit the emulator through my inet address.
However I'm still unable to edit the firestore through the UI, this error appears now:

POST http://0.0.0.0:8080/google.firestore.v1.Firestore/Write/channel?database=projects%2Fmyproj%2Fdatabases%2F(default)&VER=8&RID=57465&CVER=22&X-HTTP-Session-Id=gsessionid&%24httpHeaders=Authorization%3ABearer%20owner%0D%0AX-Goog-Api-Client%3Agl-js%2F%20fire%2F7.14.3%0D%0A&zx=ymxr29oj2iv5&t=1 net::ERR_ADDRESS_INVALID

As mentioned above, please try directly setting host to the inet address like "firestore": {"host": "172.29.180.12", "port": 8080}, in firebase.json.

Thank you @yuchenshi, setting host to the inet address like "firestore": {"host": "172.29.180.12", "port": 8080}, in firebase.json worked. I am able to edit the firestore through the UI. However, the issue with this setup is that inet addresses change frequently and it's not compatible between developers.

I see two issues here:

  1. Firestore emulator does not respond to 127.0.0.1 when asked to listen on localhost / 127.0.0.1 on WSL.

    • This may be an issue with WSL and much harder to troubleshoot.

  2. Emulator UI tries to construct an invalid URL like http://0.0.0.0:8080 when Firestore emulator is configured to listen on 0.0.0.0.

Hopefully fixing 2. can give you a reasonable workaround, and we'd appreciate any help on root-causing or working around 1.

I am going to close this in favor of https://github.com/firebase/firebase-tools-ui/issues/286 since I doubt we can solve the WSL-specific issues with localhost in a reasonable way.

If that fix is released and we still have problems with no workaround we can re-open this discussion.

I'm unable to connect to the emulator in any form when running from wsl2. None of the options for specifying the ip as the host worked. I can connect fine to the emulator UI but it can't connect either. This works the same when starting with a fresh project and an existing project.

Emulator and UI work fine on my mac.

FYI, the fix for 0.0.0.0 went out with Firebase CLI v8.6.0. Please try that if you see issues with WSL with localhost / 127.0.0.1.

It's not working. I have this configuration:
"firestore": {
"host": "0.0.0.0",
"port": "8080"
},
"ui": {
"host": "0.0.0.0",
"port": 4001
}
and I have access to ui but I cannot reach the firestore backend.
I also have firebase-tools version 8.6.
Please re-open this issue

@bartlomiejborzucki please open a new issue in the https://github.com/firebase/firebase-tools-ui repo with error messages from Firebase Emulator UI. For example, open Chrome DevTools on the UI (on the Firestore tab) and refresh to see what network requests fail and how. A screenshot can also be very helpful.

@yuchenshi
I've added new issue here: https://github.com/firebase/firebase-tools-ui/issues/332

Hi all, let's move the discussion to https://github.com/firebase/firebase-tools-ui/issues/332. I've done some Googling and summarized some workaround suggested by others at https://github.com/firebase/firebase-tools-ui/issues/332#issuecomment-666509147 with next steps for troubleshooting.

If this still affects you, make sure to check out the comments there and click the Subscribe button on that issue.

Fixed in v8.15.1. See https://github.com/firebase/firebase-tools-ui/issues/332#issuecomment-722742959 for details.

Was this page helpful?
0 / 5 - 0 ratings