Closed bartlomiejborzucki closed 4 years ago
Looks like the UI cannot reach Firestore emulator at 127.0.0.1
and thanks for providing the information. Again, this is new to me as I haven't worked with WSL before and this is most likely an WSL issue.
With that being said, I've found https://github.com/microsoft/WSL/issues/4353 seems to describe the issue you're experiencing. Would you mind updating WSL to version 18970 and disable Fast Startup and see if the issue still reproduces? You may have to install Developer Preview (or whatever they call it) to get the latest version. Once you have it and disable Fast Startup, try both localhost
and 0.0.0.0
and see which one works for you.
I had a problem with the localhost and I needed to disable Fast Startup - I'am an angular developer, and without disabling fast startup I was not able to develop my application on wsl2. Right now my application works (the only problem is a problem with IP address on firebase emulator and connection refused on localhost IP address) - TEMPORARY WORKAROUND: I need to set wsl IP address in my configuration (I've written about in the first post). I've checked localhost and 0.0.0.0 after disabled Fast Startup and I got the same result I've added these two lines to my c:/windows/system32/drivers/etc/hosts andI got the same result too :(
::1 localhost 127.0.0.1 localhost
I cannot update WSL to newest version (fast/slow ring) because of the corporate policy but IMHO I am up to date. My windows 10 version is :
Yeah I think you're up to date then. Would you mind digging into it a little bit further? Here are some steps to get you started on debugging connectivity:
Try curl http://127.0.0.1:8080/
in WSL bash, and then again in your normal Windows environment (e.g. Command Prompt or PowerShell).
Try nc -z -v 127.0.0.1 8080
as well. telnet
can also be helpful in case you don't have netcat.
Also, does replacing 127.0.0.1
with localhost
or WSL IP address help?
Just in case, please also attach firestore-debug.log
after these steps.
Ok, no problem :)
WSL PowerShell curl telnet
WSL: Power shell curl Telnet the same as power shell curl
wsl power shell curl telnet cmd
WSL powershell curl telnet the same as powershell
My firebase-debug.log firebase-debug.log
Thanks! It looks like we're out of luck here, but it bothers me that Angular and Emulator UI web server somehow work while Firestore does not. Could it be... Node.js v.s. Java? Does Realtime Database work for you then?
I'll see if I can get someone from the Firebase team to help troubleshooting this hands-on. But to be honest, I don't think there is much that we can do -- again, mostly likely changes will need to be made in WSL or Java or the Java framework used in Firestore Emulator.
Thank you very much for helping the community . I checked the realtime database and I've got the same result. I also checked Microsoft Edge - the same result. I changed port to 23123 (random number) - the same result. I also tried to add this rule:Β netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=172.18.28.xΒ and I got new error: connection reset instead of connection refused.
The workaround is here: https://github.com/microsoft/WSL/issues/5706#issuecomment-668353533
According to https://github.com/microsoft/WSL/issues/5706#issuecomment-668353533, it seems like the Firestore emulator is listening on IPv6 only when localhost
is specified. Let me also investigate on our side and see what is going on.
@yuchenshi I am doing some debugging on my personal Windows machine (WSL2).
Here's what I see from netstat -nl
when running the Firestore Emulator and the UI with all standard options:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:4000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4400 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4500 0.0.0.0:* LISTEN
tcp6 0 0 127.0.0.1:38397 :::* LISTEN
tcp6 0 0 127.0.0.1:34697 :::* LISTEN
tcp6 0 0 127.0.0.1:8080 :::* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] SEQPACKET LISTENING 13335 /run/WSL/7_interop
unix 2 [ ACC ] SEQPACKET LISTENING 14416 /run/WSL/241_interop
unix 2 [ ACC ] SEQPACKET LISTENING 14485 /run/WSL/460_interop
Now if I set the host to 0.0.0.0
in firebase.json
:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:4000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4400 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4500 0.0.0.0:* LISTEN
tcp6 0 0 :::40621 :::* LISTEN
tcp6 0 0 :::46573 :::* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] SEQPACKET LISTENING 13335 /run/WSL/7_interop
unix 2 [ ACC ] SEQPACKET LISTENING 14416 /run/WSL/241_interop
unix 2 [ ACC ] SEQPACKET LISTENING 14485 /run/WSL/460_interop
And finally with 127.0.0.1
:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:4000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4400 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4500 0.0.0.0:* LISTEN
tcp6 0 0 :::40621 :::* LISTEN
tcp6 0 0 :::46573 :::* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] SEQPACKET LISTENING 13335 /run/WSL/7_interop
unix 2 [ ACC ] SEQPACKET LISTENING 14416 /run/WSL/241_interop
unix 2 [ ACC ] SEQPACKET LISTENING 14485 /run/WSL/460_interop
So localhost
and 127.0.0.1
give the same result while 0.0.0.0
is different.
So
localhost
and127.0.0.1
give the same result while0.0.0.0
is different.
I think you meant localhost
is different while the others are the same? As seen in your snippets output, the first output has 127.0.0.1:8080
in Local Address while the two outputs has :::8080
.
But either way, ALL of these show that Firestore Emulator listening to tcp6
instead of tcp4
(or both). This is problematic, especially in the case of 127.0.0.1
and 0.0.0.0
since those are clearly IPv4. In general, Firestore Emulator should respect the chosen protocol indicated by the host IP address format.
The Emulator UI reads hosts from the config, so it tries to connect via IPv4 when 127.0.0.1
or 0.0.0.0
are used. However as you have seen, the Firestore Emulator is actually listening on IPv6, so connection fails on Windows. It works on Linux since the kernel will automatically routes these requests to the IPv6 counterpart, but WSL doesn't support that yet: https://github.com/microsoft/WSL/issues/4851.
tl;dr We should fix Firestore Emulator to listen on IPv4 when 127.0.0.1
or 0.0.0.0
is specified. If localhost
is specified, I think the spec-compliant way is to resolve localhost
and listen on ALL IP addresses returned. It usually resolves to BOTH 127.0.0.1
and ::1
from /etc/hosts
on most setups.
Another note for localhost
: If we only listen on the first resolved address, then there could be a mismatch where it resolves to ::1
in the Firestore emulator but resolves to 127.0.0.1
in the browser / curl / whatever client, or the opposite. I imagine it's even more likely to happen inside v.s. outside WSL. These issues are too hard to troubleshoot so let's not deal with that. Listening on both seems much safer.
To guard against weird hosts
files, we may also choose to special case localhost
and just hard code it to listen on both. I don't know if we should though.
I guess I'm a bit late in the conversation, but I have the same problem after i converted my WSL installation to version 2, and haven't been able to find a workaround, is there any fix yet?
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
When I try to access the UI it 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
Hi all, it tooks us quite a while to dig into the issue, but I believe we've found an effective workaround, coming with the next CLI release.
As of 8.15.1, this should work out of the box and you should be able to just reach the Firestore emulator from outside WSL without any special configuration. Make sure host
is unset or set to 127.0.0.1
(or 0.0.0.0
if you need to) in firebase.json
though, if you tried some hacks earlier. Similarly, you don't need the netsh
forwarding any more either.
Note that the workaround does disable IPv6, so please make sure Client SDKs, browsers, etc. use IPv4 127.0.0.1
as the host, e.g. useEmulator('127.0.0.1', 8080)
. I'd suggest avoiding using localhost
as the host, since some (but not all) clients may resolve that to IPv6 ::1
and connections will fail. (Don't use 0.0.0.0
on the client side either since that is not a routable IP and is known to cause issues.)
As of 8.15.1, this should work out of the box and you should be able to just reach the Firestore emulator from outside WSL without any special configuration. Make sure
host
is unset or set to127.0.0.1
(or0.0.0.0
if you need to) infirebase.json
though, if you tried some hacks earlier. Similarly, you don't need thenetsh
forwarding any more either.Note that the workaround does disable IPv6, so please make sure Client SDKs, browsers, etc. use IPv4
127.0.0.1
as the host, e.g.useEmulator('127.0.0.1', 8080)
. I'd suggest avoiding usinglocalhost
as the host, since some (but not all) clients may resolve that to IPv6::1
and connections will fail. (Don't use0.0.0.0
on the client side either since that is not a routable IP and is known to cause issues.)
Thank you for the update, I'm glad to see that we are making progress.
However, I just updated to 8.15.1, did a fresh install using the emulators codelab and I'm still unable to access the emulators UI. It does not appear fixed to me.
{ "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" }, "functions": { "source": "functions" }, "hosting": { "public": "public", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ] }, "emulators": { "functions": { "port": 5001 }, "firestore": { "port": 8080 }, "hosting": { "port": 5000 } } }
@b0ot Thanks for opening a new issue! It seems like you are indeed experiencing a different issue, since the Emulator UI isn't working for you at all, compared to all other folks here who can access the Emulator UI but not Firestore. Let's figure it out together on the new issue and I've posted some tips for troubleshooting there.
Hello, I've just updated to 8.15.1 and I'm still experiencing this issue on WSL2. I can access the Realtime DB UI, however it displays no data and there are errors in the console.
sagas.ts:48 GET http://127.0.0.1:9000/.inspect/databases.json?ns=mydb net::ERR_CONNECTION_RESET
netstat -sh gives me the following:
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:4400 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4500 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:4000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5001 0.0.0.0:* LISTEN
tcp6 0 0 :::39105 :::* LISTEN
@6apxat Does curl http://127.0.0.1:9000/.inspect/databases.json?ns=mydb
inside WSL2 (e.g. with bash
) work for you? Also, what about Firestore? (Please give it a try for the sake of debugging, even if you don't use Firestore in your project.)
Hey, just as an update. Installed the latest cli and am still seeing the issue. When I'm running things on my WSL2 machine I can start the emulators just fine, open up the UI, but when I go to /firestore
I see a spinner with "Loading collections" and eventually the page times out / goes blank.
I'll attach some screenshots of things to hopefully help? I don't have any host specified in my firebase.json
file and I see this behavior regardless of if I load http://127.0.0.1:4000/firestore
or http://localhost:4000/firestore
Happy to provide more info if needed, but don't know what would be useful so just let me know ππΎ
Current Builds are working for me.
C:\Users\crwilcox>wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
Windows 10 Pro Build: 19041.572
β― npm install -g firebase-tools
/home/crwilcox/.nvm/versions/node/v14.15.0/bin/firebase -> /home/crwilcox/.nvm/versions/node/v14.15.0/lib/node_modules/firebase-tools/lib/bin/firebase.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^2.0.6 (node_modules/firebase-tools/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.2.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ firebase-tools@8.15.0
added 1 package from 1 contributor in 17.989s
β― firebase --version
8.15.1
β― firebase emulators:start --only firestore
β― curl -4 localhost:8080 ; curl -4 127.0.0.1:8080 ; curl -6 localhost:8080 ; curl -6 [::1]:8080
Ok
Ok
curl: (7) Failed to connect to localhost port 8080: Connection refused
zsh: no matches found: [::1]:8080
C:\Users\crwilcox>curl -4 localhost:8080 & curl -4 127.0.0.1:8080 & curl -6 localhost:8080 & curl -6 [::1]:8080
Ok
Ok
curl: (7) Failed to connect to localhost port 8080: Connection refused
curl: (7) Failed to connect to ::1 port 8080: Connection refused
Also, just to be thorough.
β― cat firebase.json
{
"emulators": {
"firestore": {
"host": "::1",
"port": 8080
},
"database": {
"port": 9000
}
}
}
β― firebase emulators:start
i emulators: Starting emulators: firestore, database
β firestore: Did not find a Cloud Firestore rules file specified in a firebase.json config file.
β firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i firestore: Firestore Emulator logging to firestore-debug.log
β database: Did not find a Realtime Database rules file specified in a firebase.json config file. The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i database: Database Emulator logging to database-debug.log
i ui: Emulator UI logging to ui-debug.log
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β All emulators ready! View status and logs at http://127.0.0.1:4000 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β Emulator β Host:Port β View in Emulator UI β
βββββββββββββΌβββββββββββββββββΌββββββββββββββββββββββββββββββββββ€
β Firestore β 127.0.0.1:8080 β http://127.0.0.1:4000/firestore β
βββββββββββββΌβββββββββββββββββΌββββββββββββββββββββββββββββββββββ€
β Database β 127.0.0.1:9000 β http://127.0.0.1:4000/database β
βββββββββββββ΄βββββββββββββββββ΄ββββββββββββββββββββββββββββββββββ
Other reserved ports: 4400, 4500
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
Thanks @crwilcox ! It looks like things are working for you properly with Build 19041.572
. @6apxat @IsaiahByDayah could you please also upgrade Windows / WSL2 and see if things are working? If not, would you mind filing an issue to https://github.com/microsoft/WSL/issues and add some details (and link this issue too)? They may be able to help you further troubleshoot.
Thanks @crwilcox ! It looks like things are working for you properly with Build
19041.572
. @6apxat @IsaiahByDayah could you please also upgrade Windows / WSL2 and see if things are working? If not, would you mind filing an issue to https://github.com/microsoft/WSL/issues and add some details (and link this issue too)? They may be able to help you further troubleshoot.
Firestore seems to work OK, Realtime DB does not.
PS C:\Users\6apxa> wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
β htdocs lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
Edition Windows 10 Home Single Language
Version 20H2
Installed on βMon, β27 βApr
OS build 19042.630
Experience Windows Feature Experience Pack 120.2212.31.0
β htdocs curl --url "http://127.0.0.1:9000/.inspect/databases.json?ns=mydb"
[{"name":"mydb"}]%
β htdocs curl --url "http://127.0.0.1:8080"
Ok
PS C:\Users\6apxa> curl -Uri "http://127.0.0.1:9000/.inspect/databases.json?ns=mydb"
curl : The underlying connection was closed: An unexpected error occurred on a receive.
At line:1 char:1
+ curl -Uri "http://127.0.0.1:9000/.inspect/databases.json?ns=mydb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebReques
t], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCo
mmand
PS C:\Users\6apxa> curl -Uri "http://127.0.0.1:8080"
StatusCode : 200
StatusDescription : OK
Content : {79, 107, 10}
RawContent : HTTP/1.1 200 OK
Content-Length: 3
Ok
Headers : {[Content-Length, 3]}
RawContentLength : 3
@6apxat @IsaiahByDayah Based on https://github.com/microsoft/WSL/discussions/6240#discussioncomment-131137, you may have run into a different bug in WSL2 (fixed in 20180, probably only available through Dev / Insider builds right now). As a workaround, try changing firebase.json
to make both listen on 0.0.0.0
instead of the default 127.0.0.1
:
{
"emulators": {
"firestore": {
"host": "0.0.0.0",
"port": 8080
},
"database": {
"host": "0.0.0.0",
"port": 9000
},
"ui": {
"enabled": true,
"host": "0.0.0.0"
}
}
}
(Note the new lines for host
under both emulators plus ui
.)
And then try again with browsers and curl. Make sure to use http://127.0.0.1:PORT
as always.
EDIT: I know this can be frustrating, but the root cause is on the WSL2 side and we can only provide workarounds. Some of those workarounds can be done in the CLI (e.g. v8.15.1) but others require config changes. Either way, I believe we've done what we could on our side and the best path forward would be participating on the discussion on WSL2 repo here: https://github.com/microsoft/WSL/discussions/6240, where experts on WSL2 can help.
@yuchenshi Unfortunately the provided config didn't help. However, I can confirm that switching to Dev channel in Windows Insider Program and updating to the latest build (20262.1010) resolves this issue without any special configuration.
A little late to responding but finding the same thing as @6apxat. Switched to the dev channel in WIP and installed latest updates. Currently on 20270.1
and things are working fine.
Side note: After switching channels and updating I ran into an issue where I couldn't see my /mnt/c
drive. I ran the WSL2 kernel update again found here and that seems to have fixed everything ππΎ
@6apxat @IsaiahByDayah thank you both for following up, we're all very happy to hear that this is (probably) being fixed on the WSL side. We were running out of ideas!
Thanks for the pointers everyone. Using dev channel worked for me.
I'm not sure if this issue is related, but after a certain amount of time of heavy usage of the realtime db emulator, firestore emulator, and a local react server in wsl2, my connections all die; I cannot access either the react app or the emulator via the UI. The error I get is: ERR_CONNECTION_REFUSED
If I kill my wsl with wsl --shutdown
and restart wsl, and then spin up all the services it works fine for a bit, but eventually the problem repeats itself.
This behavior is pretty consistent. Has anyone dealt with this issue? What else can I do to troubleshoot?
The main discussion is here: https://github.com/firebase/firebase-tools/issues/2334
REQUIRED] Environment info firebase-tools:8.6.0
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
[NOT WORKING SOLUTION]
The above solution does not work
Summary: Firebase emulator is running on wsl2 and we want to open firebase-tools-ui on the host machine.The page is loaded and everything works except the connection to the firestore backend. I use the following configuration: "emulators": { "firestore": { "host": "0.0.0.0", // or host: 'localhost' or host: '127.0.0.1' "port": "8080" }, "ui": { "enabled": true, "port": 4000 } }
Workaround: Change host value to wsl2 ip address.
Screenshots: