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 can't find firebase when served on 0.0.0.0 #464

Closed
jamesncl opened this issue Dec 20, 2020 · 10 comments · Fixed by #465 or firebase/firebase-tools#2964
Closed

Emulator UI can't find firebase when served on 0.0.0.0 #464

jamesncl opened this issue Dec 20, 2020 · 10 comments · Fixed by #465 or firebase/firebase-tools#2964
Assignees
Labels
bug Something isn't working

Comments

@jamesncl
Copy link

I'm using:

  • firebase-tools v9.0.1
  • on Windows 10
  • using NVM for Windows v1.1.7
  • with Node v14.15.2.

I'm developing a Flutter app with firebase back-end, and want to test using firebase emulators running on my dev machine, and a real device running the flutter app. To achieve this I'm specifying 0.0.0.0 as the host for firebase and cloud functions in my firebase.json so that my device running the flutter app can connect to the emulators running on my dev machine using my dev machine's LAN IP:

firebase.json

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001,
      "host": "0.0.0.0"
    },
    "firestore": {
      "port": 8080,
      "host": "0.0.0.0"
    },
    "ui": {
      "enabled": true
    }
  }
}

In flutter (my dev machine LAN IP is 192.168.1.45):

String firebaseEmulatorHostName = '192.168.1.45:8080';
String cloudFunctionsEmulatorOrigin = 'http://192.168.1.45:5001';

FirebaseFirestore.instance.settings = Settings(
  host: firebaseEmulatorHostName,
  sslEnabled: false,
  persistenceEnabled: false,
);

FirebaseFunctions.instance.useFunctionsEmulator(
   origin: cloudFunctionsEmulatorOrigin,
);

This works fine. The emulators run, and the device can connect to them and read all the data from firestore.

┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://localhost:4000
└─────────────────────────────────────────────────────────────┘

┌────────────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth
├────────────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 0.0.0.0:5001 │ http://localhost:4000/functions
├────────────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 0.0.0.0:8080 │ http://localhost:4000/firestore
└────────────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at localhost:4400
Other reserved ports: 4500

The problem is that the emulator web UI on my dev machine at localhost:4000 shows the emulator UI page, but with no data in the firestore (strangely, it can see the collections, but not the documents):

Capture

I've double-checked that the documents do actually exist. The problem seems to be that the emulator can't connect to firestore, because I see this in my browser's dev console:

POST http://0.0.0.0:8080/google.firestore.v1.Firestore/Listen/channel?database=projects%2Fmyproject%2Fdatabases%2F(default)&VER=8&RID=9716&CVER=22&X-HTTP-Session-Id=SomeRedactedStuff
net::ERR_ADDRESS_INVALID

@firebase/firestore: Firestore (8.1.1): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

This seems like a bug - shouldn't the emulator translate 0.0.0.0 to localhost, or the computer's IP, or 127.0.0.1? Because as far as I understand, 0.0.0.0 isn't acutally a valid IP. I tried redirecting 0.0.0.0 to localhost using a hosts file but this doesn't seem to work.

@samtstern samtstern transferred this issue from firebase/firebase-tools Dec 21, 2020
@yuchenshi
Copy link
Member

Thanks for the bug report. This is a regression of #286 and we're looking into this.

@yuchenshi
Copy link
Member

Fixed in Firebase CLI v9.1.0.

@natebot13
Copy link

This issue still exists for the realtime database emulator. The firestore emulator UI correctly connects to 127.0.0.1, while the database emulator UI looks like it's trying to connect to 0.0.0.0. This issue looke like it's a Chrome on Windows issue, since Chrome on Windows doesn't seem to know what to do with 0.0.0.0. I haven't tested it, but it seems that Chrome on Linux can handle this and consider 0.0.0.0 as localhost.
My firebase.json looks pretty standard, with 0.0.0.0 as the host for functions, firestore, database, and auth, and all default ports

@yuchenshi
Copy link
Member

@natebot13 Your observation about Chrome on Windows v.s. Linux is right on spot, but for us to look further into this we'd need Firebase CLI version number and Chrome DevTools (Network tab showing the wrong request to 0.0.0.0 plus Console tab logs, if you see anything out of the ordinary).

@Agusfn
Copy link

Agusfn commented Feb 21, 2021

@yuchenshi I am having this same problem, but only for realtime emulator, not firestore. The web UI for firebase realtime won't work because it tries to connect to 0.0.0.0
21321

This is my firebase json file.
333

I need to set 0.0.0.0 as the host in order to access the emulator from devices in my local network as well. If I changed it to 127.0.0.1, the UI problem goes away, but i wouldn't be able to connect from my phone.

@yuchenshi
Copy link
Member

@Agusfn I think you ran into firebase/firebase-tools#2870 (a separate issue). Please try the workaround at firebase/firebase-tools#2870 (comment) and let me know if it works. If it works, we may be able to add that workaround to Emulator UI itself.

@Agusfn
Copy link

Agusfn commented Feb 24, 2021

@yuchenshi That worked! Thanks a lot. I'm not aware of how easy or not to fix this problem is, but, apparently this happens to very few people? Because I remember having it since some months ago now, and it made me reluctant to use the emulator for developing and use production which is much slower. Thank again!

@yuchenshi
Copy link
Member

yuchenshi commented Feb 24, 2021

@Agusfn This only happens to Windows users who are also using 0.0.0.0 as host, and I think it only happens after previous connection failures. It doesn't mean it's not important for the team to fix it though -- just it may take us some time to notice and identify the problem, and I really appreciate your help on that.

I've created #519 to track this issue (and @natebot13: you may want to subscribe to that one as well). I'm sorry to hear that you get reluctant to use the emulators, but we're always here to help. We look for issues like this on GitHub and you can also reach out to Firebase Support for more involved, project-specific issues.

@iamsethsamuel
Copy link

Are you sure your Firewall is not blocking the port? Try checking if the port is opened an try again. You can open the port on Ubuntu with is command sudo ufw allow 9299

@Agusfn
Copy link

Agusfn commented Oct 19, 2021

I don't think it's blocking the port since I can access the service with the proper address. It's just that for some reason the sdk wants to connect to "0.0.0.0" which doesn't make sense, given also that I've instructed already an address to connect to. That address should just represent that the service accepts incoming connections from any ip?

The repercussions of this problem for me are:

  • Every time I want to open the realtime tab on emulator UI, I have to use incognito mode.
  • (I am almost sure of this) Sometimes my mobile app on my external device (phone) in local network, just won't connect to the realtime db. When that happens, any call to the sdk will just be stuck waiting response. I have to close the app and restart it for it in order to work again.
  • If i'm using the firebase web sdk locally (on the same pc where firebase service is running) and want to connect to realtime emulator, it will throw errors about it not being able to connect to "0.0.0.0". Screenshot

It's strange that I don't see this talked about more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants