InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing
johannesjo opened this issue · comments
First of all: Thank you for this great module. It's making my life a lot easier.
Many of the users of my electron app encounter the error above. I personally was never able to reproduce it and I am not sure if this is caused by this module or just a general issue with chromium, but I am posting this here anyway in the hopes to find a new angle to tackle this problem, that has been bugging me for so long :)
I'm 99% sure it isn't this library. The library doesn't do auto-closing, and the error seems to happen in other libraries too. crbug.com seems like the right place for this.
This may happen on Mobile Safari
Issue in similar library: jensarps/IDBWrapper#80
Possible workaround: firebase/firebase-js-sdk#4059
Dexie has a workaround for this in >=3.2.1. Idb however, is closer to the native IndexedDB API and does not execute transactions in a callback as dexie does, which makes it harder to workaround "in the background" without requiring code change by its callers. But one solution would be to offer a new helper function to be used as an alternative to db.transaction()
that would return a Promise<IDBPTransaction>
- it could call nativeDB.transaction() in a try...catch and in case this error occur, do the silent database repoening (reopen the same version as was already opened). Another approach would be to let Idb's version of IDBTransaction represent just a lazy placeholder and let the actual call to nativeDB.transaction() take part in the first call to an actual request - surrounding the call to nativeDB.transaction() with a try..catch and do the workaround if needed. The latter would not require change of application code, but could introduce subtle bugs. For example, the "fake" transaction would have to support executing complete events on noop transactions (if someone calls db.transaction().oncomplete = ()=>console.log('complete')
without using the transaction).
But I assume the best thing would be if Chrome and Safari fixed the bug :)
We're still getting this issue, I was wondering if anyone has found a solution / workaround, or if it's still down to the Safari/Chrome gods?