fix(worker): inconsistent store structure due to race condition (#10536)

close #10535
This commit is contained in:
Diogo Correia
2026-01-31 01:49:35 +01:00
committed by GitHub
parent 8e2a66ece8
commit 780af09808
2 changed files with 19 additions and 9 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/worker": patch
---
Fix inconsistent store structure due to race condition.

View File

@@ -224,20 +224,25 @@ interface AddFilesFromDirResult {
function initStore ({ storeDir }: InitStoreMessage): { status: string } {
fs.mkdirSync(storeDir, { recursive: true })
try {
const hexChars = '0123456789abcdef'.split('')
for (const subDir of ['files', 'index']) {
const subDirPath = path.join(storeDir, subDir)
const hexChars = '0123456789abcdef'.split('')
for (const subDir of ['files', 'index']) {
const subDirPath = path.join(storeDir, subDir)
try {
fs.mkdirSync(subDirPath)
for (const hex1 of hexChars) {
for (const hex2 of hexChars) {
} catch {
// If a parallel process has already started creating the directories in the store,
// ignore if it already exists.
}
for (const hex1 of hexChars) {
for (const hex2 of hexChars) {
try {
fs.mkdirSync(path.join(subDirPath, `${hex1}${hex2}`))
} catch {
// If a parallel process has already started creating the directories in the store,
// ignore if it already exists.
}
}
}
} catch {
// If a parallel process has already started creating the directories in the store,
// then we just stop.
}
return { status: 'success' }
}