Skip to content

Commit 7d3e998

Browse files
committed
fix(lockfile): checkLock: handle ENOENT
1 parent 9b4b8e0 commit 7d3e998

File tree

1 file changed

+17
-7
lines changed
  • packages/mongodb-memory-server-core/src/util

1 file changed

+17
-7
lines changed

packages/mongodb-memory-server-core/src/util/lockfile.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,27 @@ export class LockFile {
7373
return LockFileStatus.available;
7474
}
7575

76-
const readout = parseInt((await fspromises.readFile(file)).toString().trim());
76+
try {
77+
const readout = parseInt((await fspromises.readFile(file)).toString().trim());
7778

78-
if (readout === process.pid) {
79-
log('checkLock: Lock File Already exists, and is for *this* process');
79+
if (readout === process.pid) {
80+
log('checkLock: Lock File Already exists, and is for *this* process');
8081

81-
return !this.files.has(file) ? LockFileStatus.available : LockFileStatus.lockedSelf;
82-
}
82+
return !this.files.has(file) ? LockFileStatus.available : LockFileStatus.lockedSelf;
83+
}
84+
85+
log(`checkLock: Lock File Aready exists, for an different process: "${readout}"`);
8386

84-
log(`checkLock: Lock File Aready exists, for an different process: "${readout}"`);
87+
return utils.isAlive(readout) ? LockFileStatus.lockedDifferent : LockFileStatus.available;
88+
} catch (err) {
89+
if (err.code === 'ENOENT') {
90+
log('checkLock: reading file failed with ENOENT');
8591

86-
return utils.isAlive(readout) ? LockFileStatus.lockedDifferent : LockFileStatus.available;
92+
return LockFileStatus.available;
93+
}
94+
95+
throw err;
96+
}
8797
}
8898

8999
/**

0 commit comments

Comments
 (0)