App Services Error: Failed host lookup

I’m getting the following error in my Flutter app when trying to run it on an Android Emulator.

Exception has occurred.

AppException (AppException: non-zero custom status code considered fatal, link to server logs: null)

The source of the error seems to be an OS Error:

Failed host lookup: 'realm.mongodb.com'

OSError (OS Error: No address associated with hostname, errno = 7)
"No address associated with hostname"

The code being called triggering the issue is the registration functionality, which is mostly just from the documentation.

final jwtCredentials = Credentials.jwt(token);
currentUser = await app.logIn(jwtCredentials); // Problematic

I’ve been trying to figure out why I suddenly started receiving this error but I am out of ideas. For a second if I skipped the errors, it would still continue and let me use my app as expected. But now I’m unable to do that either.

I haven’t changed any permissions, and I have the Internet permission added already. I do have a working internet connection and the browser on the emulator works as well. I tried restarting the emulator and my computer but that didn’t work either.

I tried with realm version 1.3.0 and 1.4.0 but I’m getting the same issue. I’m not sure what the issue is since as far as I know, I didn’t change anything. I even tried reverting anything I might have changed, but this error is still persisting. My cluster and app services are on GCP.

Appreciate any help, thanks!

You cannot lookup realm.mongodb.com from your android emulator. This is not really a realm issue.

Did you by any chance disable internet on the emulator (pull down from the top on recent emulator images).

Can you resolve the name with nslookup on your development machine?

If you can, can you do the same on the emulator:

adb shell
ping realm.mongodb.com

if this fails with

ping: unknown host realm.mongodb.com

then try google.com as well:

ping google.com

if it also fails then try:

ping 8.8.8.8

What did you learn?

BTW, A quick search with google send me to this SO thread: emulation - Android emulator not able to access the internet - Stack Overflow

Maybe it can be helpful as well

I wasn’t manually looking up realm.mongodb.com in the emulator, it’s just from Realm functionality. Also, it was working just fine for months. I didn’t disable the internet on the emulator either. Browsing through Chrome is working normally on the emulator still. Also, requests to Firebase Auth are going through normally still.

This is the output of nslookup on my machine:

nslookup
Default Server:  dns.google
Address:  8.8.8.8

> realm.mongodb.com
Server:  dns.google
Address:  8.8.8.8

Non-authoritative answer:
Name:    us-east-2.lb-b.r53.aws.cloud.mongodb.com
Address:  3.136.69.246
Aliases:  realm.mongodb.com
          global.aws.realm.mongodb.com
          global.lb-b.r53.aws.cloud.mongodb.com

Pinging all of the addresses doesn’t fail with an unknown host error, but it seems I’m getting 100% packet loss with 0 packets received. I’m not sure why this could be the case.

I’ve tried pretty much all of the suggested solutions in the SO thread but still facing the same issue.

Could you do adb shell and the suggested pings as well?
EDIT: Or did you already do that?

My apologies, I should have been clearer.

The pings on my development machine are run successfully. In the emulator using adb shell is where I’m getting the 100% packet loss.

Also, I just realized, is there a reason there is no GCP alias being shown with nslookup? If I try to visit the global gcp alias in a browser it seems to load as intended. My cluster and Atlas app are both on GCP. In case that is relevant to the situation.

On my end, when running ping under adb, it works fine (just to proof that ICMP does indeed work with realm.mongodb.com):

❯ adb -s emulator-5554 shell
emu64a:/ $ ping realm.mongodb.com
PING eu-central-1.lb-b.r53.aws.cloud.mongodb.com (35.157.33.91) 56(84) bytes of data.
64 bytes from ec2-35-157-33-91.eu-central-1.compute.amazonaws.com (35.157.33.91): icmp_seq=1 ttl=255 time=40.1 ms
64 bytes from ec2-35-157-33-91.eu-central-1.compute.amazonaws.com (35.157.33.91): icmp_seq=2 ttl=255 time=31.1 ms
64 bytes from ec2-35-157-33-91.eu-central-1.compute.amazonaws.com (35.157.33.91): icmp_seq=3 ttl=255 time=34.5 ms

We need to get your network in shape, so that the emulator can do DNS lookups. The realm SDK needs to do a DNS lookup of realm.mongodb.com, and it need to be able to connect with https on port 443.

When you say you get 100% packet loss on adb, is that for both realm.mongodb.com, google.com, and 8.8.8.8?

Also, what emulator image (API level) are you using? I’m using 33.

Interesting, I’m not sure what changed suddenly for me.

Also yes, the 100% packet loss is in adb. The pings are being sent and received just fine from my local machine, just not from adb it seems.

I’m using API level 33 as well.

What is the output of netstat -nr on adb on your end. For me it is:

emu64a:/ # netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.0.0.0        0.0.0.0         255.0.0.0       U         0 0          0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 wlan0

Another thing to consider - are you running a local firewall on your developer machine?

I general I can recommend reading the emulator docs on networking: Set up Android Emulator networking  |  Android Studio  |  Android Developers to get aquainted with the caveats

This is the output for adb on my end:

emu64xa:/ # netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.0.0.0        0.0.0.0         255.0.0.0       U         0 0          0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 wlan0

I did have a firewall initially but when issues started occurring, I disabled it. Disabling it didn’t resolve the issues.

Thanks for your help and linking the networking docs, I’ll take a look through those.