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

Emulator UI should not connect to 0.0.0.0 for emulators #286

Closed
yuchenshi opened this issue Jun 10, 2020 · 15 comments
Closed

Emulator UI should not connect to 0.0.0.0 for emulators #286

yuchenshi opened this issue Jun 10, 2020 · 15 comments

Comments

@yuchenshi
Copy link
Member

yuchenshi commented Jun 10, 2020

In firebase.json, it is possible to specify 0.0.0.0 for host for each emulator. This tells an emulator to listen on all IPv4 interfaces (including 127.0.0.1, the device's public network IP, etc.).

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

However, with this setup, the Emulator UI attempts to send requests http://0.0.0.0:8080 to reach Firestore in the Firestore viewer. This is invalid since 0.0.0.0 is a non-routable address but some browsers / platforms (such as Chrome on Linux) special cases it to mean the same as 127.0.0.1. On other browsers / platforms (such as Chrome on Windows), this fails with errors like net::ERR_ADDRESS_INVALID.

Instead, the Emulator UI should change it to 127.0.0.1 when constructing the URL. Similarly, the Emulator UI should connect to ::1 (IPv6 local) when :: (IPv6 zero) is specified.

@gautamsingal
Copy link
Contributor

@yuchenshi I would like to pick this up. As per my understanding, I think simply changing host to 127.0.0.1 in emulators would make it work. Please correct me if something else also needs to be done.

@yuchenshi
Copy link
Member Author

@gautamsingal Of course! We welcome PRs addressing this. As noted in the last paragraph, please make sure to take care of both 0.0.0.0 and :: for completeness. The best place to make the change is in server.js.

@gautamsingal
Copy link
Contributor

@yuchenshi Thanks! Picking this up

@gautamsingal
Copy link
Contributor

@yuchenshi I tried but unable to do. Can you please guide me in this?

@moneal
Copy link

moneal commented Jun 18, 2020

I'm not sure if WSL2 is part of the official supported platforms but I was unable to get any host options working when they work fine elsewhere. Using a configuration like below should work, but the emulator UI and other front-end code can't connect. I would be happy to also help.

  "firestore": {
    "host": "127.0.0.1",
    "port": 8080
  },

@blastdan
Copy link

blastdan commented Jun 18, 2020

In server.js there are the lines

Object.entries(emulators).forEach(([name, info]) => {
      json[name] = {
        hostAndPort: hostAndPort(info.host, info.port),
        ...info,
      }
    });

That host needs be checked for '0.0.0.0' and '::' If they are they should be changed to "localhost". All this logic is done using json so it makes it a bit more tricky.

I tried doing it quickly, but got stuck getting the development environment going in windows. I was getting an SCSS error about material/theme/mixins and dind't have time to work through it.

gautamsingal added a commit to gautamsingal/firebase-tools-ui that referenced this issue Jun 18, 2020
Description:
    - Added check whether info.host is not 0.0.0.0 or ::
    - If it is present, then update the host with localhost else it remains same
    - Pass the new value to hostAndPort
gautamsingal added a commit to gautamsingal/firebase-tools-ui that referenced this issue Jun 18, 2020
Description:
    - Added check whether info.host is not 0.0.0.0 or ::
    - If it is present, then update the host with localhost else it remains same
    - Pass the new value to hostAndPort
@gautamsingal
Copy link
Contributor

@blastdan Thanks for the feedback!

@moneal
Copy link

moneal commented Jun 18, 2020

@blastdan Was it a issue with node-sass and fsevents by any chance? When setting up Windows environments I commonly need to force a install and rebuild.

npm i -f fsevents
npm rebuild node-sass

@yuchenshi
Copy link
Member Author

@moneal @blastdan I think it's #210 -- a known issue. However, we still haven't found a great cross-platform solution and would appreciate any help there. Either way, let's move the discussion there.

gautamsingal added a commit to gautamsingal/firebase-tools-ui that referenced this issue Jun 18, 2020
Description:
    - Added check whether info.host is not 0.0.0.0 or ::
    - If it is present, then update the host with localhost else it remains same
    - Pass the new value to hostAndPort
@yuchenshi
Copy link
Member Author

Fixed by #312. This will be included in the next release.

@blastdan
Copy link

@yuchenshi Is there any way to track when a new release is made?

Thanks!

@yuchenshi
Copy link
Member Author

@blastdan Yes! The Emulator UI releases with the Firebase CLI, so you can head to https://github.com/firebase/firebase-tools and click on the Watch dropdown menu and select "Releases only". GitHub will notify you if there is a new release to the Firebase CLI. This will be likely included in the next one or two Firebase CLI versions.

@yuchenshi
Copy link
Member Author

FYI, this went out with Firebase CLI v8.6.0.

@arimwilson
Copy link

I am still getting this error using an event listener on the realtime database emulator. See Chrome console errors:
GET http://0.0.0.0:9000/.lp?id=1&pw=cYijYEVq0A&ser=81095532&ns=joydominoes-default-rtdb net::ERR_ADDRESS_INVALID

firebase.json says:
"emulators": {
...
"database": {
"host": "0.0.0.0"
}
...
}

firebase -V says
9.13.1

@c5n8
Copy link

c5n8 commented Feb 29, 2024

this breaks firebase/firebase-tools#1898

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

6 participants