Skip to content

Commit 313e0ac

Browse files
Ignore IndexedDb failrues during LRU
Rationale is that they the LRU task will retry its run when it is invoked next. There are no tests since the GC scheduling code is not tested right now. Let me know if you would like me to add tests. Note that there is a behavior change: If the primary lease is lost, the GC run is rescheduled. It will however get stoped in https://github.com/firebase/firebase-js-sdk/blob/5a60243bf264967819fc5c3897892084c5eb4d43/packages/firestore/src/core/component_provider.ts#L203
1 parent df44d12 commit 313e0ac

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/firestore/src/local/lru_garbage_collector.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
import { PersistencePromise } from './persistence_promise';
3333
import { TargetData } from './target_data';
3434

35+
const LOG_TAG = 'LruGarbageCollector';
36+
3537
/**
3638
* Persistence layers intending to use LRU Garbage collection should have reference delegates that
3739
* implement this interface. This interface defines the operations that the LRU garbage collector
@@ -265,13 +267,19 @@ export class LruScheduler implements GarbageCollectionScheduler {
265267
this.gcTask = this.asyncQueue.enqueueAfterDelay(
266268
TimerId.LruGarbageCollection,
267269
delay,
268-
() => {
270+
async () => {
269271
this.gcTask = null;
270272
this.hasRun = true;
271-
return localStore
272-
.collectGarbage(this.garbageCollector)
273-
.then(() => this.scheduleGC(localStore))
274-
.catch(ignoreIfPrimaryLeaseLoss);
273+
try {
274+
await localStore.collectGarbage(this.garbageCollector);
275+
} catch (e) {
276+
if (e.name === 'IndexedDbTransactionError') {
277+
logDebug(LOG_TAG, 'Ignoring IndexedDB error during LRU: ', e);
278+
} else {
279+
await ignoreIfPrimaryLeaseLoss(e);
280+
}
281+
}
282+
await this.scheduleGC(localStore);
275283
}
276284
);
277285
}

packages/firestore/test/unit/local/lru_garbage_collector.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { key, path, version, wrapObject } from '../../util/helpers';
5252
import { SortedMap } from '../../../src/util/sorted_map';
5353
import * as PersistenceTestHelpers from './persistence_test_helpers';
5454
import { primitiveComparator } from '../../../src/util/misc';
55+
import { IndexedDbTransactionError } from '../../../src/local/simple_db';
5556

5657
describe('IndexedDbLruDelegate', () => {
5758
if (!IndexedDbPersistence.isAvailable()) {

0 commit comments

Comments
 (0)