Why FirebaseRemoteConfig.fetch doesn't call its callback?
Asked Answered
G

3

8

Background

I try to use Google's new Firebase services, for A/B testing. For this, we need to use both Firebase Analytics and Firebase RemoteConfig.

The problem

Using FireBase RemoteConfig, I wanted to get the variables from the server (which have different value per variant of each experiment), but it seems that on some devices it gets stuck there, not calling its callback (OnCompleteListener.onComplete) .

I used about the same code as on the samples (here) :

    // init:
    boolean isDebug = ... ;
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(isDebug).build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    final HashMap<String, Object> defaults = new HashMap<>();
    for (...)
        defaults.put(...);
    mFirebaseRemoteConfig.setDefaults(defaults);

    //fetching the variables:
    long cacheExpiration = isDebug ? 0 : java.util.concurrent.TimeUnit.HOURS.toSeconds(1);
    mFirebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            //on some devices, I never get here at all
            if (task.isSuccessful()) {
                mFirebaseRemoteConfig.activateFetched();
                final FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(context);
                for (...) {
                    String experimentVariantValue = mFirebaseRemoteConfig.getString(...);
                    firebaseAnalytics.setUserProperty(..., experimentVariantValue);
                }
            } else {
            }
        }
    });

Thing is, the callback doesn't get called, but only on some devices:

  • Nexus 5 with Android 6.0.1 : almost always succeeds.
  • Nexus 4 with Android 5.1.1 and LG G2 with Android 4.2.2 : almost always freeze (meaning they don't get into the callback)

I've also found that when it does work, it works in the near sessions afterwards.

The question

Why does it occur? What can I do to solve this?

Gustavo answered 23/6, 2016 at 14:38 Comment(1)
I have the same problem with firebase 12.0.1Coacervate
G
1

Just to add to what Cachapa just posted, the bug happens when the fetch() is called too early. We found two solutions to the problem (both work but not satisfactory) - call the fetch() from an onResume, or add a 3 seconds delay before actually issuing the fetch().

And about the "it works in the near sessions afterwards", once you get the callback and call activateFetched(), all sessions will get the correct values.

Update The 3 second delay was from the Activity.onCreate(). After checking further, it only worked on one device - Nexus 4. It didn't do the trick on a Samsung S3 nor on a Moto X Pure. We also checked on a Samsung S7, there it worked without any delay - the problem never manifested at all.

We are discussing it in a mail correspondence with Firebase support. I will update here when they get back to me..

Update 2 Firebase team claim this is solved in GPSv9.4 and I think this time they're right. They also claimed it was solved in 9.3, but then my tests disproved it. Now (after updating our dependency on gms to v9.4), I get the callbacks correctly on my dev devices. However, I still get indications that not all of our production devices are getting the correct config. My assumption is that devices that didn't update the GPS to the latest version are still faulty, but I'm not sure..

Galer answered 29/6, 2016 at 5:32 Comment(2)
About the delay, 3 seconds from what exactly? What did you call before? The initialization (setConfigSettings, setDefaults) ?Gustavo
Did Firebase support team get back to you? Please update your answer, it would be a good help as I'm facing the same issue. Thanks :)Godrich
J
0

It seems to be some sort of race condition in the Firebase initialization code, according to this answer: https://stackoverflow.com/a/37664946

I tried quite a few of the posted workarounds and nothing worked reliably enough for my satisfaction. It seems that the Firebase devs are aware of the problem though, so the problem will probably be fixed soon.

Jewelry answered 28/6, 2016 at 14:48 Comment(2)
So it's a known bug? Can you show a more official link about it?Gustavo
Sorry, no. Someone also asked for a link to the bug in the other thread, but none was given. I assume that's because Firebase's bug tracker isn't open to the public.Jewelry
A
0

Why does it occur? What can I do to solve this?

I am guessing the reason why the callbacks do not get called is because Firebase Remote Config may have several issues and those are not solved just yet.

Below is a list of things that my team and I have found so far that may be considered as the issues of Remote Config.

Above list is some of the issues regarding Remote Config that my teammates and I have found so far. The first two of them are from Google Search, and the last one, "Debug build and Release build may affect how Remote Config behaves..?" is from our observation after testing Remote Config for a while, so we are not sure about it yet.

I am not sure if it SOLVES your problem, but if your issue is related to the first issue of what I have listed above, due to fetch() is called too early, then you may try calling fetch() with postDelayed which we have tried and it made better chance for Remote Config to successfully call its listeners, but overall, in my personal opinion, Remote Config is just not fully ready yet for production release..

Ashliashlie answered 19/7, 2016 at 1:53 Comment(2)
Yes, it seems it's being fixed. About the workaround, it didn't help in my case, but I think it got to be more rare on recent update of firebase. BTW, your 3rd item in the list doesn't have a link.Gustavo
@androiddeveloper Actually the 3rd item in the list is not what I have searched on the internet but the thing our team have thought that may be the case; this is uncertain and not sure really build variants make difference, but we found it behaves differently based on the build variants.Ashliashlie

© 2022 - 2024 — McMap. All rights reserved.