File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,21 @@ export async function lockFile(path: string): Promise<() => Promise<void>> {
5050 return setupMTimeEditor ( lockPath )
5151 } catch ( e ) {
5252 if ( e . code === 'EEXIST' ) {
53- const stat = await fsPromises . stat ( lockPath )
54- if ( performance . now ( ) - stat . mtime . getTime ( ) > mtimeLimit ) {
55- return setupMTimeEditor ( lockPath )
56- } else {
57- throw 'LOCKED'
53+ try {
54+ const stat = await fsPromises . stat ( lockPath )
55+ if ( performance . now ( ) - stat . mtime . getTime ( ) > mtimeLimit ) {
56+ return setupMTimeEditor ( lockPath )
57+ } else {
58+ throw 'LOCKED'
59+ }
60+ } catch ( e ) {
61+ if ( e . code === 'ENOENT' ) {
62+ //This will run if the lock gets released after the EEXIST error is thrown but before the stat is checked.
63+ //If this is the case, the lock acquisition should be retried.
64+ return await lockFile ( path )
65+ } else {
66+ throw e
67+ }
5868 }
5969 } else {
6070 throw e
You can’t perform that action at this time.
0 commit comments