From 87bcdd1e434027d31595fae94e542184b1dbae12 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 26 Jan 2022 20:52:50 +1100 Subject: [PATCH] Try to fix 'The database connection is closing' issues Browsers may rarely randomly close the IndexedDB connection, which would prevent the game from being able to save options or maps anymore until the user restarted the game. With this commit, the game now listens for the 'onclose' event on the IDBConnection for when the connection is unexpectedly closed - and when the 'onclose' event is raised, clears the cached IndexedDB connection global so that the next call to getDB opens a fresh IndexedDB connection. I tested this by deleting the IndexedDB database in developer tools (which triggered 'onclose' event) and seemed to work fine --- src/interop_web.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/interop_web.js b/src/interop_web.js index 129c6635c..efb7cb7ab 100644 --- a/src/interop_web.js +++ b/src/interop_web.js @@ -368,6 +368,11 @@ mergeInto(LibraryManager.library, { req.onsuccess = function() { db = req.result; window.IDBFS_db = db; + // browser will sometimes close connection behind the scenes + db.onclose = function(ev) { + console.log('IndexedDB connection closed unexpectedly!'); + window.IDBFS_db = null; + } callback(null, db); }; req.onerror = function(e) {