From 047db02a658b631743a8674a283147db81e1f7af Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Fri, 8 May 2026 10:30:05 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Add=20extra=20check=20for?= =?UTF-8?q?=20SQLite=20errors=20(#3258)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/workers/sqlite-worker.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/addons/api/addon/workers/sqlite-worker.js b/addons/api/addon/workers/sqlite-worker.js index f260f6e42..f16b89631 100644 --- a/addons/api/addon/workers/sqlite-worker.js +++ b/addons/api/addon/workers/sqlite-worker.js @@ -97,15 +97,25 @@ import { if (poolUtil.getCapacity() > 20) { await poolUtil.removeVfs(); } - } else { + } else if ( + err?.resultCode === SQLITE_CORRUPT || + err instanceof WebAssembly.RuntimeError + ) { + // We might have gotten ourselves into a bad state which corrupted the DB so clear it out and retry. console.error('SQLite initialization error:', err); - - // We might have gotten ourselves into a bad state which corrupted the DB so clear it out and retry - if (err?.resultCode === SQLITE_CORRUPT) { + try { + if (db) { + db.close(); + db = null; + } poolUtil.unlink(`/${dbName}`); - } else { - throw err; + } catch (cleanupErr) { + // If cleanup fails, wipe the entire VFS and reinstall to start fresh + console.error('SQLite cleanup error:', cleanupErr); + await poolUtil.removeVfs(); } + } else { + throw err; } } }