Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(security): avoid recovery guard fsync convoy

Rahmanc2ebe7854b8c
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 5d5e6e6a..0f2d6a9c 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -8,6 +8,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `security` avoid recovery guard fsync convoy
- `jobs` finish retention before releasing runtime
- `runtime` preserve fallback recovery readiness
- `runtime` keep service starts on shared exclusion
diff --git a/lib/security-store-lock.ts b/lib/security-store-lock.ts
index b01f34b7..6586d044 100644
--- a/lib/security-store-lock.ts
+++ b/lib/security-store-lock.ts
@@ -69,6 +69,22 @@ async function openExclusive(lockPath: string, token: string): Promise<HeldLock>
return { token };
}
+async function openRecoveryGuard(lockPath: string, token: string): Promise<HeldLock> {
+ // Recovery guards are never auto-broken: if their owner crashes at any point,
+ // leaving even an empty guard behind is intentionally fail-closed. Unlike the
+ // primary lock, there is therefore no need to fsync a candidate before trying
+ // to publish it. O_EXCL rejects losing contenders before they write/fsync,
+ // avoiding an fsync convoy when many callers wait on one security store.
+ const handle = await fs.open(lockPath, "wx", 0o600);
+ try {
+ await handle.writeFile(token, "utf8");
+ await handle.sync();
+ } finally {
+ await handle.close().catch(() => undefined);
+ }
+ return { token };
+}
+
async function release(lockPath: string, held: HeldLock): Promise<void> {
const owner = await fs.readFile(lockPath, "utf8").catch(() => "");
// Never remove a lock that a recovery path may have handed to another process.
@@ -88,7 +104,7 @@ async function acquire(lockPath: string, timings: Required<SecurityStoreLockTimi
// published live lock at the same pathname (a classic check/unlink ABA race).
let gate: HeldLock | null = null;
try {
- gate = await openExclusive(recoveryPath, `${process.pid}:${randomUUID()}`);
+ gate = await openRecoveryGuard(recoveryPath, `${process.pid}:${randomUUID()}`);
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
}