mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-13 19:47:48 -04:00
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.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
"cafs",
|
||||
"camelcase",
|
||||
"canonicalizer",
|
||||
"cantopen",
|
||||
"canva",
|
||||
"cerbos",
|
||||
"certfile",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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' }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user