From d5534557329de72fb07594535b67d401a84e2ee4 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 6 Apr 2026 17:39:44 -0500 Subject: [PATCH] fix(gsd): only unlink notification lock when owned, prevent foreign lock deletion _withLock() was unconditionally unlinking the lock file in finally, even when lock acquisition failed. This could delete another process's lock and allow unlocked concurrent writes. Now tracks ownership and only cleans up locks we created. --- src/resources/extensions/gsd/notification-store.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/resources/extensions/gsd/notification-store.ts b/src/resources/extensions/gsd/notification-store.ts index 54a600061..d79d4a33c 100644 --- a/src/resources/extensions/gsd/notification-store.ts +++ b/src/resources/extensions/gsd/notification-store.ts @@ -275,14 +275,19 @@ function _withLock(basePath: string, fn: () => T): T { } } + // Only run the mutation if we actually own the lock + const ownsLock = fd !== null; try { - // Write our PID timestamp into the lock for stale detection - if (fd !== null) { + if (ownsLock && fd !== null) { + // Write our PID timestamp into the lock for stale detection writeFileSync(lockPath, String(Date.now()), "utf-8"); closeSync(fd); } return fn(); } finally { - try { unlinkSync(lockPath); } catch { /* best-effort cleanup */ } + // Only delete the lock if we created it — never remove another process's lock + if (ownsLock) { + try { unlinkSync(lockPath); } catch { /* best-effort cleanup */ } + } } }