Unable to call firestore from content provider of background app in Android 15 (targetSdk=35)
[REQUIRED] Step 2: Describe your environment
- Android Studio version: Android Studio Ladybug | 2024.2.1 Patch 1
- Firebase Component: Firestore
- Component version: firebase-bom = "33.5.1"
[REQUIRED] Step 3: Describe the problem
Since updating my Pixel 7a to Android 15 (and updating my apps' targetSdkVersion to 35), I've been seeing this in the logs. My app calls the content provider of one of my other apps. The other app (as part of its startup logic) calls firestore.
My working assumption, is that Android 15 has added new restrictions on background apps (i.e. the one with the content provider) accessing the internet. If this is correct, it would be good if the log message better reflected this. Or if there was an appropriate way for the app to first check this restriction before calling firestore.
(25.1.1) [WatchStream]: (b476562) 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
at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)
at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:124)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:632)
at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219)
at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
}.
Hi @marcardar
Thanks for your report! Could you please share more info about this? For example, how long have you noticed this issue happened? Is there any Firebase SDK upgrade in your content provider in the last half year? Do you see it before the content provider upgrading Firestore SDK?
I only started noticing this in the past couple of weeks. Roughly around the time I updated my device to Android 15 and my apps to target Android 15. I frequently update my Firebase SDK version when the stable version is released. In the past month these were when I updated the firestore SDK:
Oct 31: firebase-bom = "33.5.1" Oct 22: firebase-bom = "33.5.0"
I've been using the content provider in this way for over a year. It's not so much that the content provider is causing a problem, but I suspect more that the app is accessing firestore from the background.
Hi @marcardar , we didn't find any release on Android 15 relates to restriction of background app connectivity issue so far. I will make a note for this, and update you if we have any findings. In the meantime, if you find anything might be related to this issue, please feel free to leave a comment.
What else could be causing it. If I launch the app directly, the log errors do not occur. If the app is accessed via the content provider, then the log errors do occur. This is 100% reproducible on my end. I'm at a loss of what could be causing it.
I noticed that the error also happens straight after the app goes in the background (e.g. after pressing Home). So it's more general than originally thought. i.e. the only reason it was happening when accessing the content provider was because at that moment the app was in the background. So, to reproduce: Launch app (and note no errors from Firestore) then press Android Home, and then we see this in the logs:
I Application backgrounded at: timestamp_millis: 1731076358815
V Read error: ssl=0xb400007a99a2d558: I/O error during system call, Software caused connection abort
V Write error: ssl=0xb400007a99a2d558: I/O error during system call, Broken pipe
D tagSocket(5) with statsTag=0xffffffff, statsUid=-1
V SSL shutdown failed: ssl=0xb400007a99a2d558: I/O error during system call, Success
W (25.1.1) [WatchStream]: (477e11e) Stream closed with status: Status{code=UNAVAILABLE, description=End of stream or IOException, cause=null}.
<truncated>
I'm experiencing the same issue - albeit only tested so far in emulator environment. I'm running Pixel 7 API 35, inside Android Studio. I get the error when when the app is in the background and the app receives a push notification which has an image link.
Here I have a Pixel 8 with Android 15. In my case, I put the app in the background and I have a worker running after some time. I always get the same error.
@romaopedro did you solve the issue with Unable to resolve host?
Same. Pixel 7.
I've noticed that the grpc version is 1.62.2
Version v1.65.0 has a bugfix that might be related:
services: restore //services:binarylog bazel target (https://github.com/grpc/grpc-java/pull/11292) (https://github.com/grpc/grpc-java/commit/d57f2719b20bd2d929b23413196c70d930ae40f6). This fixes a regression introduced in 1.62.2
None of the less, maybe worth updating grpc version.
I didn't test with new versions. Need to give it a try.
https://developer.android.com/about/versions/15/behavior-changes-all#background-network-access
In Android 15, apps that start a network request outside of a valid process lifecycle receive an exception. Typically, an UnknownHostException or other socket-related IOException. Network requests that happen outside of a valid lifecycle are usually due to apps unknowingly continuing a network request even after the app is no longer active.
To mitigate this exception, ensure your network requests are lifecycle aware and cancelled upon leaving a valid process lifecycle by using lifecycle aware components. If it is important that the network request should happen even when the user leaves the application, consider scheduling the network request using WorkManager or continue a user visible task using Foreground Service.
I fixed my Flutter code lazylily by turning the Firestore network off when the app is in the background. (Native Android can be done similarly I think)
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.hidden) {
unawaited(FirebaseFirestore.instance.disableNetwork());
} else if (state == AppLifecycleState.resumed) {
unawaited(FirebaseFirestore.instance.enableNetwork());
}
}
I guess for android it is https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner
Assuming you don't have services , mainly activities
Latest firebase-bom 33.11.0, (Flutter firebase_core 3.13.0) fixed the warning. No need to change any.
33.11.0
(25.1.3) [WatchStream]: (475a6b9) 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 (Ask Gemini) at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223) at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282) at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) Caused by: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:124) at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103) at java.net.InetAddress.getAllByName(InetAddress.java:1152) at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:632) at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219
This happens straight after the app goes into background. Sad.
But can't reproduce the bug in a release build. Hopeful.