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 exception - Unable to resolve host firestore.googleapis.com, #3302

Closed
itaishalom opened this issue Jan 11, 2022 · 12 comments
Closed
Assignees

Comments

@itaishalom
Copy link

itaishalom commented Jan 11, 2022

Hi all.
I'm using latest firebase_cloud release to flutter (3.1.6) but I think it's the sdk issue.
I have the following on my code:

result = await FirebaseFirestore.instance .collection( 'fields') .get(GetOptions(source: Source.server));

Which works fine.
But!
Sometime after the screen of my phone (Pixel 3a android 12, samsung galaxy a12 android 11) goes off, after a while i see the following exception:

W/ManagedChannelImpl( 7914): [{0}] Failed to resolve name. status={1}
W/Firestore( 7914): (24.0.0) [WatchStream]: (f8463fe) Stream closed with status: Status{code=UNAVAILABLE, description=Unable to resolve host firestore.googleapis.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host “firestore.googleapis.com”: No address associated with hostname
W/Firestore( 7914): at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)
W/Firestore( 7914): at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
W/Firestore( 7914): at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
W/Firestore( 7914): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/Firestore( 7914): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/Firestore( 7914): at java.lang.Thread.run(Thread.java:923)
W/Firestore( 7914): Caused by: java.net.UnknownHostException: Unable to resolve host “firestore.googleapis.com”: No address associated with hostname
W/Firestore( 7914): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
W/Firestore( 7914): at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
W/Firestore( 7914): at java.net.InetAddress.getAllByName(InetAddress.java:1152)
W/Firestore( 7914): at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:631)
W/Firestore( 7914): at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219)
W/Firestore( 7914): ... 5 more
W/Firestore( 7914): Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
W/Firestore( 7914): at libcore.io.Linux.android_getaddrinfo(Native Method)
W/Firestore( 7914): at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:73)
W/Firestore( 7914): at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:202)
W/Firestore( 7914): at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:73)
W/Firestore( 7914): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
W/Firestore( 7914): ... 9 more
W/Firestore( 7914): }.

When I resume my app, and the above code is called again i get exception:

ERROR: [cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
I/flutter ( 7914): #0 MethodChannelQuery.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart:110:7)
I/flutter ( 7914):
I/flutter ( 7914): #1 _JsonQuery.get (package:cloud_firestore/src/query.dart:390:9)
I/flutter ( 7914):

Any Idea what causes it?
I tried to call retries on the above get() but the same error occurred. The workaround is calling terminate on the firestore object and then recall the above get() and it seem to solve it.

@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@itaishalom itaishalom changed the title Firestore exception Firestore exception - Unable to resolve host firestore.googleapis.com, Jan 11, 2022
@argzdev
Copy link
Contributor

argzdev commented Jan 11, 2022

Hi @itaishalom, thanks for your report. We'll try to investigate this and see what we can find. In the meantime, since this is a flutter app, may I ask if you've tried reporting at https://github.com/firebaseextended/flutterfire? You may get better help there. Also if you could provide us an MCVE, it'll help speed up our investigation as well.

@itaishalom
Copy link
Author

Thanks for reply!
I'm familiar with the flutter firebase guys and from previous issues i can see that they suggest opening the issue here.
Furthermore i can see that the first exception came from java and the firestore exception comes from the method channel, which means, from the native SDK.
If I were trying to write an mvce in Android, i would create a simple app with Main activity and call the get() function on onResume().
Note: server only is must on the options.

@argzdev
Copy link
Contributor

argzdev commented Jan 26, 2022

Sorry for the delayed response and thanks for the extra details, @itaishalom. However, I'm unable to repro the issue. Here's a code snippet of what I tried:

    override fun onResume() {
        super.onResume()
        getData()
    }

    fun getData(){
        val db = Firebase.firestore
        val result = db.collection("users")
        result.get(Source.SERVER)
            .addOnSuccessListener { documents ->
                if (documents != null) {
                    for(doc in documents) Log.d(TAG, "DocumentSnapshot data: ${doc.id}")
                } else {
                    Log.d(TAG, "No such document")
                }
            }
            .addOnFailureListener { exception ->
                Log.d(TAG, "get failed with ", exception)
            }
    }

Am I missing anything? Could you help answer a few questions for me to narrow down the issue:

  1. Any extra steps that you took in order to experience this behavior?
  2. How long is was the phone off before it countered this issue?
  3. Is this issue reproducible in other devices? Such as an emulator or other phones?
  4. How often can you reproduce this issue? Is it consistent?

Also this looks like a duplicate of #2637, it could be a regression or the fix hasn't been applied to the latest version of Flutter.
Have you tried reaching out to the Flutter team about this?

FWIW, I've also noticed that this issue was experienced by another dev, you could check out his alternative solution here, while we try and resolve this.

@itaishalom
Copy link
Author

itaishalom commented Jan 30, 2022

Hi, thanks for reply.
It happens very often, it happened on multiple devices on various of android releases.
The phone's screen is off for seconds to moments.
The plugin of flutter is aligned with your releases.
The code you wrote does the same as the my Flutter code so I don't understand really why you don't see this but it makes me wonder if there's something missing on the plugin.

@cedricboidin
Copy link

Hi all,
I experience some problems were data takes a long time to be updated after the app returns to the foreground. The symptoms are exactly those of issue #2637, although I use the latest Firebase version (firebase-bom:29.0.4) where the bug is supposed to be fixed.

When I get the problem and have a look at the logs, I see the error mentioned in this issue:

01-29 17:27:58.322 30136 30171 W Firestore: (24.0.1) [WatchStream]: (d82cdfe) Stream closed with status: Status{code=UNAVAILABLE, description=Unable to resolve host firestore.googleapis.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname

I was able to reproduce the behavior with the following code :

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        auth = Firebase.auth
        setContentView(R.layout.activity_main)

        auth.signInWithEmailAndPassword("xxx@xxx.com", "xxx")
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    val db = Firebase.firestore
                    val result = db.collection("pocfirestore")
                        .orderBy("createdAt", Query.Direction.DESCENDING)
                        .limit(1)

                    result.addSnapshotListener { documents, e ->
                        if (documents != null) {
                            for (doc in documents) {
                                val textView = findViewById<TextView>(R.id.text);
                                val text = doc.data.get("createdAt")

                                if (text is Timestamp) {
                                    textView.text = "last message created at ${text.toDate().toString()}"
                                }
                            }
                        }
                    }
                }
            }
    }

@argzdev
Copy link
Contributor

argzdev commented Jan 31, 2022

Hi @itaishalom & @cedricboidin, thanks for the extra details, I was now able to repro the issue. I used the same steps given in #2637. I'll notify an engineer and see what we can do here.

@wu-hui
Copy link
Contributor

wu-hui commented Feb 1, 2022

So this is a grpc-java issue which has been reported here: grpc/grpc-java#8850

In the issue there is a link to a potential fix, we will be working with grpc team to get this released ASAP.

Will update this issue when it is fixed.

@wu-hui wu-hui self-assigned this Feb 1, 2022
@d9media
Copy link

d9media commented Feb 22, 2022

I have the same in simulator android

W/ManagedChannelImpl( 5303): [{0}] Failed to resolve name. status={1}
W/Firestore( 5303): (24.0.0) [WatchStream]: (aa0cab) Stream closed with status: Status{code=UNAVAILABLE, description=Unable to resolve host firestore.googleapis.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
W/Firestore( 5303): 	at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)

@Joseph-Nathan
Copy link

i have the same problem , in many users , but it may work if the user restart his getaway or change the network he use ,
i thinks it with DNS internet service provider and firestore .

@brainunknown
Copy link

I had a similar issue (Unable to resolve host "firestore.googleapis.com": No address associated with hostname) when using the android emulator. But using the real smartphone I don´t have this issue.

Another tip is: Can it be related with firebase AppCheck?

@cedricboidin
Copy link

It seems that version 24.0.2 of firebase-firestore includes the GRPC fix and solves the issue.

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

No branches or pull requests

8 participants