From cf7d2b5078b7210c24e7eb8655e59206156d8c92 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 31 Jan 2020 10:14:21 -0800 Subject: [PATCH 1/4] Ignore primary lease loss in maybeGarbageCollectMultiClientState This ignores the error if the primary lease is somehow lost between updateClientMetadataAndTryBecomePrimary() and maybeGarbageCollectMultiClientState(). There is no special recovery logic needed as the next primary will run the periodic GC. Fixes https://github.com/firebase/firebase-js-sdk/issues/2555 --- packages/firestore/src/local/indexeddb_persistence.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index 8d77ede55fb..6c5771ce25f 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -72,6 +72,7 @@ import { ReferenceSet } from './reference_set'; import { ClientId } from './shared_client_state'; import { TargetData } from './target_data'; import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db'; +import {ignoreIfPrimaryLeaseLoss} from "./local_store"; const LOG_TAG = 'IndexedDbPersistence'; @@ -489,7 +490,7 @@ export class IndexedDbPersistence implements Persistence { ).next(() => inactive); }); } - ); + ).catch(err => ignoreIfPrimaryLeaseLoss(err).then(() => [])); // Delete potential leftover entries that may continue to mark the // inactive clients as zombied in LocalStorage. From 22555dff21cdb0b77a3344cf07cd2771f86b42f2 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 31 Jan 2020 10:14:29 -0800 Subject: [PATCH 2/4] [AUTOMATED]: Prettier Code Styling --- packages/firestore/src/local/indexeddb_persistence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index 6c5771ce25f..e267dc4ffd3 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -72,7 +72,7 @@ import { ReferenceSet } from './reference_set'; import { ClientId } from './shared_client_state'; import { TargetData } from './target_data'; import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db'; -import {ignoreIfPrimaryLeaseLoss} from "./local_store"; +import { ignoreIfPrimaryLeaseLoss } from './local_store'; const LOG_TAG = 'IndexedDbPersistence'; From bd33328338832e34c6686d6d9294dd407a367e47 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 31 Jan 2020 10:17:31 -0800 Subject: [PATCH 3/4] Remove cyclic dependency --- packages/firestore/src/local/indexeddb_persistence.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index e267dc4ffd3..1f79cbe268b 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -72,8 +72,6 @@ import { ReferenceSet } from './reference_set'; import { ClientId } from './shared_client_state'; import { TargetData } from './target_data'; import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db'; -import { ignoreIfPrimaryLeaseLoss } from './local_store'; - const LOG_TAG = 'IndexedDbPersistence'; /** @@ -490,7 +488,12 @@ export class IndexedDbPersistence implements Persistence { ).next(() => inactive); }); } - ).catch(err => ignoreIfPrimaryLeaseLoss(err).then(() => [])); + ).catch(() => { + // Ignore primary lease violations or any other type of error. + // We don't use `ignoreIfPrimaryLeaseLoss` since we don't want to depend + // on LocalStore. + return []; + }); // Delete potential leftover entries that may continue to mark the // inactive clients as zombied in LocalStorage. From 57bc363332fe97ff4aafc583b82877fa4b07cefd Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 31 Jan 2020 10:30:40 -0800 Subject: [PATCH 4/4] Update indexeddb_persistence.ts --- packages/firestore/src/local/indexeddb_persistence.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index 1f79cbe268b..7209456f574 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -489,8 +489,9 @@ export class IndexedDbPersistence implements Persistence { }); } ).catch(() => { - // Ignore primary lease violations or any other type of error. - // We don't use `ignoreIfPrimaryLeaseLoss` since we don't want to depend + // Ignore primary lease violations or any other type of error. The next + // primary will run `maybeGarbageCollectMultiClientState()` again. + // We don't use `ignoreIfPrimaryLeaseLoss()` since we don't want to depend // on LocalStore. return []; });