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

fix(firestore, android): synchronize access to firestore instances #16675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading