Skip to content

Commit 9851714

Browse files
author
Oracle Public Cloud User
committed
fix(session): guard fallback lock cleanup with reentrancy check
The original fallback unconditionally force-removed the lock file whenever pid matched, which broke reentrant lock semantics — the first release in a reentrant pair would remove the file while another holder still expected it to exist. Now checks sessionLockHeldByThisProcess before the fallback cleanup. If any reentrant holder remains, the lock file is preserved as sidecar-lock intends.
1 parent 39cb851 commit 9851714

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/agents/session-write-lock.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,12 +991,14 @@ export async function acquireSessionWriteLock(params: {
991991
const release = async () => {
992992
await innerRelease();
993993
// Fallback cleanup: if sidecar-lock's removeLockIfUnchanged failed
994-
// due to snapshot mismatch, force-remove the lock file if we still
995-
// own it (pid matches current process).
994+
// due to snapshot mismatch, force-remove the lock file if no
995+
// reentrant holder remains and the file still matches our pid.
996996
try {
997-
const payload = await readLockPayload(lockPath);
998-
if (payload?.pid === process.pid) {
999-
await fs.rm(lockPath, { force: true });
997+
if (!sessionLockHeldByThisProcess(normalizedSessionFile)) {
998+
const payload = await readLockPayload(lockPath);
999+
if (payload?.pid === process.pid) {
1000+
await fs.rm(lockPath, { force: true });
1001+
}
10001002
}
10011003
} catch {
10021004
// Best-effort fallback on filesystem errors.

0 commit comments

Comments
 (0)