Skip to content

Commit 9b2a9b2

Browse files
committed
Add 10 second timeout to IDB operations
possibly related to TurboWarp#981 ?
1 parent 3bb7ae6 commit 9b2a9b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/common/idb.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const TRANSACTION_TIMEOUT_MS = 10 * 1000;
2+
13
// https://github.com/jakearchibald/safari-14-idb-fix/blob/582bbdc7230891113bfb5743391550cbf29d21f2/src/index.ts
24
const idbReady = () => {
35
const isSafari =
@@ -113,10 +115,20 @@ class Database {
113115
* @param {function} reject
114116
*/
115117
Database.setTransactionErrorHandler = (transaction, reject) => {
118+
const timeoutId = setTimeout(() => {
119+
reject(new Error('Transaction timed out'));
120+
transaction.abort();
121+
}, TRANSACTION_TIMEOUT_MS);
122+
123+
transaction.oncomplete = () => {
124+
clearTimeout(timeoutId);
125+
};
116126
transaction.onerror = (e) => {
127+
clearTimeout(timeoutId);
117128
reject(new Error(`Transaction error: ${e.target.error}`))
118129
};
119130
transaction.onabort = () => {
131+
clearTimeout(timeoutId);
120132
reject(new Error('Transaction aborted'));
121133
};
122134
};

0 commit comments

Comments
 (0)