From ec9dd3b1391c6c0bd63f02cd684149af8d0d75bf Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 3 Apr 2026 15:37:52 +0200 Subject: [PATCH] fix: avoid SQLite race condition during store initialization on Windows The worker's initStore eagerly opened the SQLite index database, racing with the main thread's StoreIndex constructor. On Windows with mandatory file locking this caused SQLITE_CANTOPEN. The worker now initializes its StoreIndex lazily on first use. Also fixed bare .catch() creating an unhandled promise rejection. --- cspell.json | 1 + store/controller/src/storeController/index.ts | 2 +- worker/src/start.ts | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cspell.json b/cspell.json index 16918ff1b3..d8edfdf864 100644 --- a/cspell.json +++ b/cspell.json @@ -28,6 +28,7 @@ "cafs", "camelcase", "canonicalizer", + "cantopen", "canva", "cerbos", "certfile", diff --git a/store/controller/src/storeController/index.ts b/store/controller/src/storeController/index.ts index 751ed81438..fa6b06d5f4 100644 --- a/store/controller/src/storeController/index.ts +++ b/store/controller/src/storeController/index.ts @@ -44,7 +44,7 @@ export function createPackageStore ( ): StoreController { const storeDir = initOpts.storeDir if (!fs.existsSync(path.join(storeDir, 'files'))) { - initStoreDir(storeDir).catch() + initStoreDir(storeDir).catch(() => {}) } const cafs = createCafsStore(storeDir, { cafsLocker: initOpts.cafsLocker, diff --git a/worker/src/start.ts b/worker/src/start.ts index cd93a972d9..784126707a 100644 --- a/worker/src/start.ts +++ b/worker/src/start.ts @@ -276,8 +276,10 @@ function initStore ({ storeDir }: InitStoreMessage): { status: string } { } } } - // Initialize the SQLite index database - getStoreIndex(storeDir) + // The SQLite index database will be initialized lazily by getStoreIndex() + // on the first operation that needs it (e.g., readPkgFromCafs, addFilesFromDir). + // Eagerly opening it here races with the main thread's StoreIndex constructor, + // which can cause SQLITE_CANTOPEN on Windows due to mandatory file locking. return { status: 'success' } }