Overview
I'm using Flutter with Firebase. After the phone/app enters Doze Mode, Firebase needs a few minutes (too long!) to reconnect. It took me weeks to find how to reproduce this issue.
Steps to reproduce:
Open a Flutter app and select a screen where you can call Firebase with a click of a button
Enter Androids' Doze Mode (Lock the screen, run adb shell dumpsys battery unplug, and then run adb shell dumpsys deviceidle force-idle)
After a few seconds/minutes, under the "Run" tab, the following will appear:
Stream closed with status: Status{code=UNAVAILABLE, description=Keepalive failed. The connection is likely gone, cause=null}.and[{0}] Failed to resolve name. status={1}Now, unlock your phone and try to make a Firebase query
For me, the following error appears 8 out of 10 times. The connection will re-establish after hitting the "Retry" button, but only after a few minutes which is, of course, too late.
W/XXX.XXXXXXX(14214): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed) W/XXX.XXXXXXX(14214): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed) W/Firestore(14214): (22.0.1) [WatchStream]: (72436f2) 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(14214): at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:436) W/Firestore(14214): at io.grpc.internal.DnsNameResolver$Resolve.resolveInternal(DnsNameResolver.java:272) W/Firestore(14214): at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:228) W/Firestore(14214): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/Firestore(14214): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/Firestore(14214): at java.lang.Thread.run(Thread.java:919) W/Firestore(14214): Caused by: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname W/Firestore(14214): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156) W/Firestore(14214): at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103) W/Firestore(14214): at java.net.InetAddress.getAllByName(InetAddress.java:1152) W/Firestore(14214): at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:646) W/Firestore(14214): at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:404) W/Firestore(14214): ... 5 more W/Firestore(14214): Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname) W/Firestore(14214): at libcore.io.Linux.android_getaddrinfo(Native Method) W/Firestore(14214): at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74) W/Firestore(14214): at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200) W/Firestore(14214): at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74) W/Firestore(14214): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135) W/Firestore(14214): ... 9 more W/Firestore(14214): }. W/XXX.XXXXXXX(14214): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed) I/flutter (14214): MyDatabase | getDatabaselData | [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.
The caught exception is: MyDatabase | getDatabaselData | [cloud_firestore/unavailable] The service is currently unavailable.
Pubspec.yaml
cloud_firestore: ^0.14.1+3
firebase_storage: ^4.0.1
firebase_core: ^0.5.0+1
firebase_auth: ^0.18.3