Skip to content

Commit ff41093

Browse files
committed
fix windows race condition
1 parent e938026 commit ff41093

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

workspaces/libnpmexec/lib/with-lock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function acquireLock (lockPath) {
8787
}
8888
if (status === 'stale') {
8989
// there is a very tiny window where another process could also release the stale lock and acquire it before we release it here; the lock compromise checker should detect this and throw an error
90-
deleteLock(lockPath)
90+
deleteLock(lockPath, ['ENOENT', 'EBUSY']) // on windows, EBUSY can happen if another process is creating the lock; we'll just retry
9191
}
9292
return await acquireLock(lockPath)
9393
}
@@ -100,12 +100,12 @@ function acquireLock (lockPath) {
100100
})
101101
}
102102

103-
function deleteLock (lockPath) {
103+
function deleteLock (lockPath, ignoreCodes = ['ENOENT']) {
104104
try {
105105
// synchronous, so we can call in an exit handler
106106
rmdirSync(lockPath)
107107
} catch (err) {
108-
if (err.code !== 'ENOENT') {
108+
if (!ignoreCodes.includes(err.code)) {
109109
throw err
110110
}
111111
}

workspaces/libnpmexec/test/with-lock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ t.test('concurrent stale lock takeover', async (t) => {
133133
withLock(lockPath, () => 'lock2'),
134134
withLock(lockPath, () => 'lock3'),
135135
])
136+
console.log(results)
136137
// all locks should either be successfully acquired or get compromised (expected occasional race condition)
137138
t.ok(results.every(result => result.status === 'fulfilled' || result.status === 'rejected' && result.reason.code === 'ECOMPROMISED'))
138139
})

0 commit comments

Comments
 (0)