fix: recover from malformed instance lock files
Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
@@ -76,7 +76,9 @@ export function acquireProcessInstanceFileLock(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ownerPid = readLockOwnerPid(lockPath);
|
ownerPid = readLockOwnerPid(lockPath);
|
||||||
if (ownerPid && !isPidAlive(ownerPid) && existsSync(lockPath)) {
|
const shouldTreatAsStale =
|
||||||
|
ownerPid === undefined || !isPidAlive(ownerPid);
|
||||||
|
if (shouldTreatAsStale && existsSync(lockPath)) {
|
||||||
try {
|
try {
|
||||||
rmSync(lockPath, { force: true });
|
rmSync(lockPath, { force: true });
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -77,4 +77,20 @@ describe('process instance file lock', () => {
|
|||||||
expect(readFileSync(lockPath, 'utf8')).toBe('5555');
|
expect(readFileSync(lockPath, 'utf8')).toBe('5555');
|
||||||
lock.release();
|
lock.release();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('replaces malformed lock file content', () => {
|
||||||
|
const userDataDir = createTempDir();
|
||||||
|
const lockPath = join(userDataDir, 'clawx.instance.lock');
|
||||||
|
writeFileSync(lockPath, 'not-a-pid', 'utf8');
|
||||||
|
|
||||||
|
const lock = acquireProcessInstanceFileLock({
|
||||||
|
userDataDir,
|
||||||
|
lockName: 'clawx',
|
||||||
|
pid: 6666,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(lock.acquired).toBe(true);
|
||||||
|
expect(readFileSync(lockPath, 'utf8')).toBe('6666');
|
||||||
|
lock.release();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user