Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Do not attempt to re-use IndexedDB transactions
Browse files Browse the repository at this point in the history
In Firefox v52, LocalStore#saveKeys() triggered a
TransactionInactiveError when trying to concurrently save the encryption
key and password hint to the database. The request to save the key
started a new IDB transaction and the request to save the hint attempted
to re-use that transaction.

This worked before when using Q.Promise but broke with the recent switch
to native Promises, possible due to the issues discussed in
dexie/Dexie.js#317

Since transaction re-use is just an optimization, the problem is worked
around for the moment by just avoiding re-use.
  • Loading branch information
robertknight committed Oct 17, 2016
1 parent 405f85a commit c21a5ce
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lib/base/key_value_store.ts
Expand Up @@ -176,28 +176,13 @@ export class IndexedDBDatabase implements Database {
class IndexedDBStore implements ObjectStore {
private db: Promise<IDBDatabase>;

// the active transaction, if any.
// Transactions are started automatically when any
// operation occurs. This field is cleared when
// the transaction becomes closed for new requests,
// which happens when control returns to the event loop
private transaction: IDBTransaction;

constructor(database: Promise<IDBDatabase>, public storeName: string) {
this.db = database;
}

private getStore(db: IDBDatabase) {
if (!this.transaction) {
// start a new transaction. As per the IDB spec, this transaction
// remains active until control returns to the event loop, at which
// point it becomes closed for new requests
this.transaction = db.transaction(this.storeName, 'readwrite');
Promise.resolve(true).then(() => {
this.transaction = null;
});
}
return this.transaction.objectStore(this.storeName);
const tx = db.transaction(this.storeName, 'readwrite');
return tx.objectStore(this.storeName);
}

set<T>(key: string, value: T): Promise<void> {
Expand Down

0 comments on commit c21a5ce

Please sign in to comment.