Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TestSuite][Android][Database] Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance #97

Closed
greena13 opened this issue May 8, 2017 · 5 comments
Labels
Platform: Android Service: Database Firebase Realtime Database

Comments

@greena13
Copy link
Contributor

greena13 commented May 8, 2017

I suspect this one may be a "won't fix", but I thought I'd document it nonetheless.

When running any of the database tests in the test suite app after having refreshed the app, the following error is raised in the Android logs:

Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance

I believe this is because setPersistenceEnabled() is being called each time the database is accessed for the first time after the app is refreshed. This exception is not thrown the first time the app is opened and the database tests are run - only after a refresh, does it occur.

It seems refreshing clears the state of the JS (so the boolean flag maintained there for whether firebase has persistence enabled already) is cleared, however the firebase database (whatever singleton is returned by mFirebaseAuth = FirebaseAuth.getInstance();) is not cleared. So the JS thinks it's setting persistence for the first time, but it's not.

I've tried moving this flag into the Java code, but this too, seems to be reset when the test app is refreshed.

Unfortunately, there is no documented way to query the FirebaseDatabase instance directly, to inspect it's persistence state, that I could find.

I am not sure if this is some side effect of the way the test application is wired to react-native-firebase and whether normal consumers of the library are also seeing this error while they develop their applications.

This issue also does not appear to be causing any change in behaviour - just the exception being thrown - but it would be good to resolve this issue if anyone can come up with a solution.

@Ehesp
Copy link
Member

Ehesp commented May 8, 2017

#5

I'll close mine in favour of this one as it contains more information.

@Salakar
Copy link
Member

Salakar commented May 8, 2017

image

This is already wrapped in a try catch for this reason I believe, does the error log contain that snippet from the logging line? "FirebaseDatabase setPersistenceEnabled exception"

@greena13
Copy link
Contributor Author

greena13 commented May 8, 2017

Appologies, @Ehesp - I didn't see your earlier issue at the time of posting. :/

Right you are, @Salakar. With fresh eyes, the error is indeed appearing in the Android logs because it is being caught and logged.

  1. Is there definitely no way to prevent this error from happening by querying the FirebaseDatabase instance somehow, to establish whether it's already had persistence enabled? i.e. does anyone have a better idea than the following:

  2. Is there a way to effectively swallow this exception that only hides false negatives? Making the catch clause more specific is the obvious first step, but is there any other state or mechanism we could employ to keep track of the persistence between app refreshes?

@Salakar
Copy link
Member

Salakar commented May 8, 2017

Seems like a few people have faced the same issue on android: http://stackoverflow.com/questions/37448186/setpersistenceenabledtrue-crashes-app

Something like the second answer would work probably, or we could just remove the log of the catch, was only there to catch this issue really.

@greena13
Copy link
Contributor Author

greena13 commented May 9, 2017

I've removed the logging of com.google.firebase.database.DatabaseException at this point in the code.

Salakar added a commit that referenced this issue May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android Service: Database Firebase Realtime Database
Projects
None yet
Development

No branches or pull requests

3 participants