1

I am using Firestore in my app. According to the documentation, it supports offline data persistence and when the network is on again, Firestore synchronizes changes.

Here is my code.

FirebaseFirestore db = FirebaseFirestore.getInstance();
User user = new User();
db.collection("users").document("doc").set(user);

It works as expected: it caches locally if the network is off and synchronizes when the network is on again. But I keep getting this warning:

W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}

This post says it is due to no internet connection. If Firestore supports offline persistence, why do I get this warning? How to get rid of this warning?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Marat
  • 1,288
  • 2
  • 11
  • 22
  • Are you getting it once or you keep on getting it multiple times? If you get multiple times, is it stoping at some point in time or is constantly displaying the warning? – Alex Mamo Oct 09 '19 at 12:42
  • Yes, keep getting multiple times without stopping unless the network is on and it is synchronized – Marat Oct 09 '19 at 13:20
  • Ok, I'll write you an answer right away. – Alex Mamo Oct 09 '19 at 13:21

1 Answers1

1

It works as expected: it cashes locally if the network is off and synchronizes when the network is on again.

That's the expected behaviour.

But I keep getting this warning:

W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}

This post says it is due to no internet connection.

That post it right, it's because of no internet connection.

If Firestore supports offline persistence, why do I get this warning?

You get it because between the time when you regain the internet connection and the time when the listener actually becomes active, there is an amout of time in which your client is not connected to the server. That's the reason why that warning is printed out multiple times without stopping unless the network is on and the client is synchronized again with the server.

The reason that the retries aren't happening so quickly as you expect is because the code that performs the retries is using a so called exponential backoff algorithm. This means that this code prevents all the retries that can happen on user's device so quickly in favor of performance. Too many retries can also affect the user by consuming too much bandwith of the his data plan.

When you are listening for changes in a Cloud Firestore database and you have some network disconnects, this what is happening and unfortunately there isn't much you can do. You don't have any control on how Firebase Firestore SDK manages its connections.

How to get rid off this warning?

IMO, since it's only a warning and not an Exception and it is displayed only for a few seconds till the connection is reestablished, you can simply ignore it.

But if you really want to get rid of it, the code below might help you. Please note, that I haven't tested yet.

InstantiatingGrpcChannelProvider channelProvider = InstantiatingGrpcChannelProvider.newBuilder()
    .setKeepAliveTime(Duration.ofSeconds(60L))
    .setKeepAliveTimeout(Duration.ofMinutes(5L))
    .build();

FirestoreOptions firestoreOptions = FirestoreOptions.newBuilder()
    .setChannelProvider(channelProvider).build();

FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
    .setCredentials(credentials).setFirestoreOptions(firestoreOptions)
    .setConnectTimeout(5000).setReadTimeout(5000).build();
FirebaseApp firebaseApp = FirebaseApp.initializeApp(firebaseOptions);

Firestore firestore = FirestoreClient.getFirestore(firebaseApp);
Community
  • 1
  • 1
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193