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 committed Nov 15, 2024
1 parent a80a2ef commit 5743c80
Showing 1 changed file with 11 additions and 7 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 :
synchronized (firestoreInstanceCache) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
if (entry.getValue().getInstance().getApp().getName().equals(appName)
if (entry.getValue().getInstance().getApp().getName().equals(appName)
&& entry.getValue().getDatabaseURL().equals(databaseURL)) {
return entry.getKey();
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 :
synchronized (firestoreInstanceCache) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
FirebaseFirestore firestore = entry.getKey();
Tasks.await(firestore.terminate());
FlutterFirebaseFirestorePlugin.destroyCachedFirebaseFirestoreInstanceForKey(
FirebaseFirestore firestore = entry.getKey();
Tasks.await(firestore.terminate());
FlutterFirebaseFirestorePlugin.destroyCachedFirebaseFirestoreInstanceForKey(
firestore);
}
}
removeEventListeners();

Expand Down

0 comments on commit 5743c80

Please sign in to comment.