Skip to content

Commit

Permalink
fix(firestore, android): synchronize access to firestore instances (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored and Lyokone committed Dec 4, 2024
1 parent b36794b commit 03e85ae
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ protected static void setCachedFirebaseFirestoreInstanceForKey(

protected static FirebaseFirestore getFirestoreInstanceByNameAndDatabaseUrl(
String appName, String databaseURL) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
if (entry.getValue().getInstance().getApp().getName().equals(appName)
&& entry.getValue().getDatabaseURL().equals(databaseURL)) {
return entry.getKey();
synchronized (firestoreInstanceCache) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
if (entry.getValue().getInstance().getApp().getName().equals(appName)
&& entry.getValue().getDatabaseURL().equals(databaseURL)) {
return entry.getKey();
}
}
}
return null;
Expand Down Expand Up @@ -200,12 +202,14 @@ public Task<Void> didReinitializeFirebaseCore() {
() -> {
try {
// Context is ignored by API so we don't send it over even though annotated non-null.
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
FirebaseFirestore firestore = entry.getKey();
Tasks.await(firestore.terminate());
FlutterFirebaseFirestorePlugin.destroyCachedFirebaseFirestoreInstanceForKey(
firestore);
synchronized (firestoreInstanceCache) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
FirebaseFirestore firestore = entry.getKey();
Tasks.await(firestore.terminate());
FlutterFirebaseFirestorePlugin.destroyCachedFirebaseFirestoreInstanceForKey(
firestore);
}
}
removeEventListeners();

Expand Down

0 comments on commit 03e85ae

Please sign in to comment.