From 6fd6ea9b8e47860cd072af65e97c427a388de14e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 12 Apr 2017 14:42:01 +0100 Subject: [PATCH] rageshake: fix race when collecting logs *apparently* it's possible for your indexeddb transaction to complete in the background, so that the `oncomplete` handler is never called. Make sure that the oncomplete handler is set *before* doing the work. --- src/vector/rageshake.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vector/rageshake.js b/src/vector/rageshake.js index 0e5b5dac..a6a18370 100644 --- a/src/vector/rageshake.js +++ b/src/vector/rageshake.js @@ -205,9 +205,6 @@ class IndexedDBLogStore { } let txn = this.db.transaction(["logs", "logslastmod"], "readwrite"); let objStore = txn.objectStore("logs"); - objStore.add(this._generateLogEntry(lines)); - let lastModStore = txn.objectStore("logslastmod"); - lastModStore.put(this._generateLastModifiedTime()); txn.oncomplete = (event) => { resolve(); }; @@ -219,6 +216,9 @@ class IndexedDBLogStore { new Error("Failed to write logs: " + event.target.errorCode) ); } + objStore.add(this._generateLogEntry(lines)); + let lastModStore = txn.objectStore("logslastmod"); + lastModStore.put(this._generateLastModifiedTime()); }); return this.flushPromise; }