IDBWrapper icon indicating copy to clipboard operation
IDBWrapper copied to clipboard

Failed to execute 'transaction' on ' IDBDatabase': The database connection is closing

Open mojoaxel opened this issue 7 years ago • 18 comments

In Chrome sometimes the following error appears:

Failed to execute 'transaction' on ' IDBDatabase': The database connection is closing

Sadly to this point I can not say in which line of code because it is hard to reproduce this.

mojoaxel avatar Aug 11 '17 08:08 mojoaxel

see also

  • https://github.com/pouchdb/pouchdb/issues/3415#issuecomment-71058793
  • https://github.com/remotestorage/remotestorage.js/issues/939
  • https://stackoverflow.com/questions/27201761/indexeddb-deletedatabase-throws-error
  • https://bugs.chromium.org/p/chromium/issues/detail?id=146284

mojoaxel avatar Aug 11 '17 08:08 mojoaxel

Thanks for reporting this! And, sorry for the late reply.

Are you deleting a database before the error occurs? Because this is the only place where IDBWrapper closes a connection. If not, it would look like some "accidental closing".

jensarps avatar Oct 20 '17 12:10 jensarps

Are you deleting a database before the error occurs? Because this is the only place where IDBWrapper closes a connection. If not, it would look like some "accidental closing".

I cannot reproduce it yet, but It happend sometimes with a client. After reading a lot about it I think it is a Chrome bug. maybe Chrome closes the Connection after a given time, or if low on memory or something... The only thing that could help here is a better Error Handling in IDBWrapper, but I don't know where to put it.

@jensarps At the moment I'm waiting it the problem still exists in current Chrome versions. If so I'll come back to you.

mojoaxel avatar Oct 23 '17 07:10 mojoaxel

If it was indeed Chrome closing the connection by itself, the only way to guard against that would be to check the connection before every transaction – which is something I'd rather not do.

So, let's wait and see if the issue still exists – and hope for the best :)

jensarps avatar Oct 25 '17 09:10 jensarps

'POSTS' to 'posts'

rogervolz avatar Jan 30 '18 16:01 rogervolz

@jensarps how can i fix this problem if i deleted the database from chrome application tools?

joesleiman avatar Sep 03 '18 13:09 joesleiman

Same thing is keep happening to me. when you will try to access the indexDb store before it gets ready this error will arise.

amrendra007 avatar Oct 16 '18 06:10 amrendra007

Just stumbled over this thread: I have the same problem in Safari 12.0.1 (13606.2.104.1.2) and Chrome (Version 70.0.3538.102 (Offizieller Build) (64-Bit) - both Mac: [Error] Unhandled Promise Rejection: InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.

I got the error when recreating/reopening the IDB.

I am explicitly closing/droping the indexedDB when the user logs out and got this error message when the user logs in (where the DB will be recreated/opened). Even the error message shows up I can access the IDB after recreation. This is the code on logout (no error message on this):

`function dbDrop() {

db.close();

var request = indexedDB.deleteDatabase('gameDB');

request.onsuccess = function () {
    console.log ("done");
};

request.onerror = function () {
    alert ("fehler");
};

request.onblocked = function () {
    alert ("fehler");
};

}`

Firefox (Mac) is the only browser that doesn't show the message above on re-login.

Taygair avatar Nov 23 '18 11:11 Taygair

I am solving it this way. Just to help in case anyone still has this same problem screen shot 2018-12-04 at 10 42 59 am .

amrendra007 avatar Dec 04 '18 05:12 amrendra007

Hi,

Glad I found that thread since we are running into that issue. We put a good amount of analysis and tracking on this - some of our numbers are in this spreadsheet - and these are our findings:

  1. It happens only on iOS and Safari/Safari Web Kit
  2. A spot check of reporting IPs in the source data set seems to point to this issue being limited to cellular connections
  3. It seems that the clients can't really recover from this (although this might be specific to our implementation)

I will check out the recommendations for fixes above and report back.

Any ideas of anyone needs more data feel free to hit me up.

R.

rupert-huelsey-tally avatar Aug 15 '20 03:08 rupert-huelsey-tally

I am getting this error in the Safari mobile browser as well when I try to log into my website via Firebase OAuth.

bensultan1985 avatar Sep 23 '20 02:09 bensultan1985

I've been unable to reproduce this myself, but lots of other people do seem to have this issue: https://github.com/johannesjo/super-productivity/labels/db

johannesjo avatar Oct 02 '20 19:10 johannesjo

Have also recently encountered this on Linux / Chromium.

Evernote Web Clipper 7.13.5.4-0198c22 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
Clipper core: 1.5.0-ca0a537
Locale: en-US
3989856 experiments status:
{
 "SaveButtonPos_CLIPPER-1768": null,
 "ClipTypeOrder_CLIPPER-1992": null
}

2020\12\3 23:32:03 WRN: DB set value error: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
 InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing. 

edit : while using EverNote web clipper, which seems to be using IDBWrapper under the hood.

SR-G avatar Dec 04 '20 13:12 SR-G

Some browser might tend to loose connection every [I don't know] seconds/minutes/hours.

The solution is to reload the connection, I do it every 10 minutes:

setInterval(() => {
  console.log('IndexedDB reload: closing connection');
  opennedDB.close();
  setTimeout(() => {
    const a = window.indexedDB.open('yourdb', 1);
    a.onsuccess = event => {
      console.log('IndexedDB reload: successful');
    }
  }, 100)
}, RELOAD_INDEXEDDB_PERIOD);

fabcotech avatar Feb 06 '21 12:02 fabcotech

I also had this problem. Some customers reported that this error occurred after the computer resume from hibernation Electron 9.1.2. But I didn't find any useful information, I sure that my program does not close the database connection

everlose avatar Mar 09 '21 08:03 everlose

It appears as if a firebase client upgrade (we went to 8.x) reliably solves the issue - no more error messages here. Check out their change log - there are a lot of references in the release notes regarding this issue. Went from 5.x to 8.x without major hassle. https://firebase.google.com/support/release-notes/js#8.1.2

rupert-huelsey-tally avatar Mar 09 '21 20:03 rupert-huelsey-tally

Any changes here? Have the same problem on iPad OS without Cellular. Cannot reproduce, just getting via BugMonitoring. I'm not using IndexedDB directly but using LokiJS with IndexedDB Adapter for fallback / persistance.

ssgnoe avatar Feb 15 '22 13:02 ssgnoe

This error occurred to me when I had no space left on my device. Even after clearing some space it still happend, had to restart my application

MauritzFunke avatar Dec 28 '22 10:12 MauritzFunke