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

Firestore emulator on wsl2 does not work, results in ERR_CONNECTION_REFUSED #5706

Closed
bartlomiejborzucki opened this issue Aug 3, 2020 · 6 comments

Comments

@bartlomiejborzucki
Copy link

bartlomiejborzucki commented Aug 3, 2020

WSL 2 is the only platform where firebase emulator is not working properly. I don't know where is the problem. I think that maybe it is related to WSL2 so I've added the following bug here. IMHO Firebase emulator is ok because I can use it on Linux Machine or MacOS machine without any problems.

Environment

windows 10 build 19041.388
WSL2 (ubuntu from Ms Store)
firebase-tools:8.6.0

Steps to reproduce

  • install and set firebase invironment on WSL2
  • use the following configuration:
    "emulators": {
    "firestore": {
    "host": "0.0.0.0", // or host: 'localhost' or host: '127.0.0.1'
    "port": "8080"
    },
    }
  • firebase emulators:start

more hints you can find here:
firebase/firebase-tools#2334
firebase/firebase-tools-ui#332

Expected behavior

We should be able to connect to firestore backend emulator hosted on WLS2

Actual behavior

Connection is refused.
Here I've added information about connection problem firebase/firebase-tools-ui#332 (comment)
In each case, I've changed firestore IP address (file firebase.json)

@sirredbeard
Copy link
Contributor

sirredbeard commented Aug 3, 2020

From screenshots at firebase/firebase-tools-ui#332 (comment) it appears that it is connecting fine in bash in WSL but not from PowerShell on Windows

#4150 dupe?

@therealkenc
Copy link
Collaborator

therealkenc commented Aug 3, 2020

There's no CLI repro steps in the OP, and I quit at what is no doubt a problem between keyboard and chair on firebase init. Pasting firebase emulator:start returns Error: emulator:start is not a Firebase command (its emulators). The json posted isn't well formed the brackets aren't matched Unexpected token ':'. Attention span ended there.

#4150 dupe?

Possibly #4851 with a side of #5298 based on firebase/firebase-tools-ui#332. It can probably be lit up absent #4150.

What does netstat -nl return after firebase is started.

@therealkenc
Copy link
Collaborator

therealkenc commented Aug 4, 2020

I've jumped though what appear to be plausible firebase setup hoops, including registering a firebasehello in the console along with firebase init with option selections that also seem plausible.

$ curl -sL https://firebase.tools | bash
$ mkdir 5706 && cd 5706
$ firebase init
$ # select UI and firestore

Edited the resulting firebase.json thus:

{
  "emulators": {
    "firestore": {
      "port": 8080,
      "host": "0.0.0.0"
    },
    "ui": {
      "enabled": true,
      "port": 8081,
      "host": "0.0.0.0"
    }
  }
}

Then start:

image

The seems to take on 20180, WSL2, Ubuntu 20.04. From Edge and Powershell:

image

image

image

Looking at the netstat -nl:

image

That tcp6 ::: 8080 is problematic on WSL2 ref #4851 (message), or at least used to be. #5298 went fixinbound in June, so whatever that was I won't be experiencing it on 20180.

General off-the-record guidance for 19041 would be to eschew localhost. A better way to roll is use avahi-daemon spiritually similar the sandstorm thread #5368 (message). That will get you real IP address instead of localhost, or typing the server address manually. TL;DR, sudo service dbus start and sudo service avahi-daemon start, after editing /etc/avahi/avahi-daemon.conf. Looks like:

image

For accessing firebase from elsewhere (LAN,WAN), that is perennial favorite #4150 as Hayden alluded. For web services like firebase, a http proxy on the Windows side is one way to skin that cat. Some folks are using port forwarding. YRMV. HTH.

@bartlomiejborzucki
Copy link
Author

Hi,
Thanks for the advice. I double-checked this issue #4150 (and workaround) and it's really working! The first time, I checked the solution with a huge amount of likes - #4150 (comment) - and I failed. I got errors on PowerShell console 😅. But the second time I used the script from this comment #4150 (comment) and Firebase emulator has started to work properly 😃 😃 😌.
I've added these ports to the following script:

$Ports =(22,80,443,8080,10000,3000,5000,5001,8081,4200,3128,4400,4500)

Thank you.

Thank you for additional advice related to using the localhost during development. Maybe the community should prepare a blog post or tutorial about working with the localhost on WSL2. There is a lot of information on GitHub about it but not in the same place 😟.

@goleary
Copy link

goleary commented Aug 20, 2020

For anyone else that ends up here, don't forget to update your firebase.json files with:

{
  ...
  "emulators": {
    "firestore": {
      "port": 8080,
      "host": "0.0.0.0"
    },
    "ui": {
      "enabled": true,
      "port": 8081,
      "host": "0.0.0.0"
    }
  }
}

The solution @bartlomiejborzucki mentions didn't work for me until I added this.

@b0ot
Copy link

b0ot commented Oct 13, 2020

Can someone please summarize these instructions into one post for the workaround?

I'm pretty sure I've tried most of the suggestions and nothing thus far is working and I'm guessing different suggestions may interfere with one another.

Thus far I have

  • Disabled fast startup
  • Attempted all sorts of IP settings with 0.0.0.0 (fail)
  • Attempted to access the firestore via my WSL2 Ubuntu IP address (fail)
  • Modified my Powershell settings to enable running scripts
  • Ran the updated script linked at the bottom of #4150 (comment)
    After adding additional ports: 22,80,443,8080,10000,3000,4000,5000,5001,8081,8082,4200,3128,4400,4500
    Direct Script: Here
    (fail)

When I try to access the UI it simply says "Not Found"

  • When back and ran the script directly in the comment after adding the additional ports.
    The UI simply says "Not Found"

Initial Error from the first Script here

PS C:\Users\tom\OneDrive\Documents\WSL Linux fix> .\wsl2-network.ps1
Remove-NetFireWallRule : No MSFT_NetFirewallRule objects found with property 'DisplayName' equal to 'WSL 2 Firewall
Unlock'.  Verify the value of the property and retry.
At C:\Users\tom\OneDrive\Documents\WSL Linux fix\wsl2-network.ps1:32 char:1
+ Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock';
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (WSL 2 Firewall Unlock:String) [Remove-NetFirewallRule], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_DisplayName,Remove-NetFirewallRule

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

No branches or pull requests

5 participants