firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
216 stars 35 forks source link

[Bug] Android devices alert users that they are offline when Firestore tries to connect without internet connection #1079

Open pstpetrov-dev opened 1 month ago

pstpetrov-dev commented 1 month ago

Description

Since we updated to Firebase 12 some users are reporting that their Android devices alert them that they are offline when Firestore tries to syncs without internet connection. If the device is not online the following is observed every 3-5 seconds which seems to trigger an "Offline" message on the Android device and users can't use the app. The app is designed to work offline and this never happened on prior Firebase versions.

Not sure if it is necessarily a bug, but is there a way to suppress the message?

Thank you! Relevant manifest lines: `

`

Reproducing the issue

Unity App with a Firestore listener which works when the device is online Turn off Internet in the device Start the app and observe the message every 3-5 seconds in Logcat The Firestore sync attempt seems to generate a message on the Android device alerting the user that the device is offline

Firebase Unity SDK Version

12.0.0 and 12.1.0

Unity editor version

2022.3.39f1

Installation Method

.unitypackage

Problematic Firebase Component(s)

Firestore

Other Firebase Component(s) in use

Analytics, Authentication, Crashlytics, Remote Config

Additional SDKs you are using

No response

Targeted Platform(s)

Apple Platforms, Android

Unity editor platform

Mac

Scripting Runtime

IL2CPP

Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

Relevant Log Output

2024-07-29 14:00:33.635 14515-14719 ManagedChannelImpl      com.bundle      W  [{0}] Failed to resolve name. status={1}
2024-07-29 14:00:35.842 14515-14710 Firestore               com.bundle       W  (25.0.0) [WriteStream]: (aa9c84b) 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:156)
                                                                                                        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) 
                                                                                                    Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
                                                                                                        at libcore.io.Linux.android_getaddrinfo(Native Method)
                                                                                                        at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:133)
                                                                                                        at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:222)
                                                                                                        at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:133)
                                                                                                        at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
                                                                                                        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) 
                                                                                                    }.

If using CocoaPods for Apple platforms, the project's Podfile.lock

Expand Podfile.lock snippet
```yml 👀 Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

argzdev commented 1 month ago

Thanks for reaching out, @pstpetrov-dev.

Update: Just to make sure were on the same page, could you clarify a few things for me:

  1. When you mentioned "Firestore listener", do you mean the listener for getting realtime updates with Cloud Firestore?
  2. You mentioned that "Firestore sync attempt seems to generate a message on the Android device alerting the user that the device is offline". The warning in the stacktrace should only be displayed in your logcat, is this somehow being shown to your users?
  3. Any chance you could share code snippets?

I tried testing this with Firestore both 11.9.0 and 12.1.0 with slight deviation from your steps:

  1. Run app
  2. Turn on airplane mode
  3. Trigger Firestore real time updates
  4. UnknownHostException is observed, but it looks like it has backoff retry so it doesn't repeat every 3-5 seconds.

Is this the behavior you're also encountering?

google-oss-bot commented 1 month ago

Hey @pstpetrov-dev. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

pstpetrov-dev commented 1 month ago

Hey @argzdev

  1. When you mentioned "Firestore listener", do you mean the listener for getting realtime updates with Cloud Firestore?

Yes, see attached txt file for code snippets Listeners.txt

  1. You mentioned that "Firestore sync attempt seems to generate a message on the Android device alerting the user that the device is offline". The warning in the stacktrace should only be displayed in your logcat, is this somehow being shown to your users?

Yes, they get a native popup on their Android device a few seconds after app start. See attached user provided video (around 0:27).

https://github.com/user-attachments/assets/bd8a1d5f-51b3-48e5-93f6-6f76793f7c60

  1. Any chance you could share code snippets?

See code provided in point 1. Let me know if you need anything specific please. These listeners start when the app starts and are active throughout.

I tried testing this with Firestore both 11.9.0 and 12.1.0 with slight deviation from your steps:

  1. Run app
  2. Turn on airplane mode
  3. Trigger Firestore real time updates
  4. UnknownHostException is observed, but it looks like it has backoff retry so it doesn't repeat every 3-5 seconds.

Is this the behavior you're also encountering?

No, I see the error appearing every 3-5 seconds as if the code is retrying the connection. I believe this was observed after we updated to 12.0.0.

VanHop94 commented 3 weeks ago

Hi. Recently, my application cannot open when the device is offline. When I open my app it will open Google Play immediately. I see Logcat and I'm sure this issue comes from Firebase. I don't know how to fix it. Please help me

pstpetrov-dev commented 2 weeks ago

@argzdev were you and the team able to pinpoint where the issue is?

argzdev commented 2 weeks ago

Thank you for your patience. I've tried testing multiple scenarios with something similar to your code snippet:

protected void GetRealtimeValue()
    {
      Query doc1 = db.Collection("col1").Document("doc1").Collection("collection1");
      ListenerRegistration listener1 = doc1.Listen(snapshot =>
      {
        foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
        {
          DebugLog(documentSnapshot.Id);
        }
      });

      Query doc2 = db.Collection("col2").Document("doc2").Collection("collection2");
      ListenerRegistration listener2 = doc2.Listen(snapshot =>
      {
        foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
        {
          DebugLog(documentSnapshot.Id);
        }
      });

      Query doc3 = db.Collection("col3").Document("doc3").Collection("collection3");
      ListenerRegistration listener3 = doc3.Listen(snapshot =>
      {
        foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
        {
          DebugLog(documentSnapshot.Id);
        }
      });
    }

And I was able to retrieve the same stacktrace after turning off the internet, but no native pop ups are shown:

2024/08/30 19:04:25.896 22462 22563 Warn ManagedChannelImpl [{0}] Failed to resolve name. status={1}
2024/08/30 19:04:26.573 22462 22557 Warn Firestore (25.0.0) [WatchStream]: (edb787e) 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
2024/08/30 19:04:26.573 22462 22557 Warn Firestore  at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)
2024/08/30 19:04:26.573 22462 22557 Warn Firestore  at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
2024/08/30 19:04:26.573 22462 22557 Warn Firestore  at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
2024/08/30 19:04:26.573 22462 22557 Warn Firestore  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
2024/08/30 19:04:26.573 22462 22557 Warn Firestore  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
2024/08/30 19:04:26.573 22462 22557 Warn Firestore  at java.lang.Thread.run(Thread.java:1012)

This is working as intended, AFAIK this stacktrace will be appear since the real time listener is trying to reconnect to the internet to receive updates. However, like I previously mentioned this stacktrace warning will only show up in your logcat.

The native pop up is not a feature we have in Firestore that would automatically show up or redirect to Google Play. This is most likely due to something else entirely unrelated to our SDKs.

That said, if you have reason to believe that Firestore is causing this popup issue, kindly provide an MCVE so we can investigate this further. Thanks!

google-oss-bot commented 1 week ago

Hey @pstpetrov-dev. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

pstpetrov-dev commented 1 week ago

Hi. Recently, my application cannot open when the device is offline. When I open my app it will open Google Play immediately. I see Logcat and I'm sure this issue comes from Firebase. I don't know how to fix it. Please help me

@VanHop94 Were you able to localize it to Firebase? If so can you produce a sample project where this happens? I don't see the error on my test Android devices, so can't reproduce it.

google-oss-bot commented 6 hours ago

Hey @pstpetrov-dev. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!