[GH-ISSUE #7801] [Issue]: Stale writer lease is never reclaimed on Windows when the MachineGuid probe times out (1 s budget, first reg.exe call takes ~2 s) — follow-up evidence for #6674 #4308

Closed
opened 2026-10-21 06:14:39 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @boricha417 on GitHub (Oct 19, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7801

Originally assigned to: @SpicyMarinara on GitHub.

Summary

After a force-killed server, the next start fails in storage.open with StorageWriterLeaseError naming a PID that no longer exists, and the lease is never reclaimed automatically. Root cause, measured on this machine: the win32 readStableMachineId() probe (reg.exe query ... MachineGuid, timeout: 1_000) intermittently times out because the first reg.exe call in a Node process takes ~1.8–2.0 s here, so the process runs with CURRENT_HOST_ID = null and cannot prove it is on the same host as the existing lease. This is the evidence #6674 asked for.

Expected behavior

A lease left behind by a process that no longer exists on the same machine and the same boot should be recognised as stale (the staleReason = "pid" path) and reclaimed without manual file deletion.

Actual behavior

Startup aborts with:

StorageWriterLeaseError: Another Marinara Engine process (PID 45540, host MY-PC) may be using
C:\...\Marinara-Engine\packages\server\data\storage. Close it before retrying. If it no longer exists,
verify every process is stopped and remove only C:\...\packages\server\data\storage\.writer-lease.

PID 45540 did not exist. The only way out was deleting data/storage/.writer-lease by hand, as the message suggests. The dead-PID check is never reached because host identification fails first (analysis below).

Steps to reproduce

  1. On a Windows machine where the first reg.exe call from a Node process exceeds 1 s (here: consistently ~1.8–2.0 s across 4 separate Node processes, see Measurements), run the server once at a time when the probe happens to succeed, so a lease with a real hostId exists. (On this machine that was the case on 2026-10-17; the probe is intermittent.)
  2. End that server from outside (Task Manager "End task", power loss) so the lease stays behind.
  3. Start the server again at a time when the probe fails (times out). The new process now has CURRENT_HOST_ID = null.

Result: StorageWriterLeaseError on every launch until .writer-lease is removed manually.

A deterministic variant for a test: write a v4 lease record with a non-null hostId and a dead PID, then start a process whose CURRENT_HOST_ID is null (e.g. make the reg.exe probe fail). acquireWriterLease() throws instead of reclaiming.

Environment

  • Marinara Engine version: 2.5.0, commit c56501495 (main). The previous checkout was also 2.5.0 (7e2823696, 2026-10-07); git diff between the two shows no change in file-backed-store.ts or writer-boot-id-cache.ts, so the same lease code produced a lease with a hostId on 2026-10-17 and without one on 2026-10-19.
  • Install type: source (Git checkout, start.bat launcher, auto-update enabled)
  • OS + version: Windows 11 Pro, build 10.0.26200 (x64). Node.js v24.19.0, pnpm 10.34.5 via Corepack. Antivirus: Windows Defender only (real-time protection on), no third-party AV.
  • Browser or app shell: N/A (the server fails before serving anything)
  • Data directory: packages\server\data\storage on the local NTFS system drive (C:)

Logs, screenshots, or video

Startup failure (pino JSON, reformatted):

level 50  event "startup.failed"  stage "storage.open"
msg "[startup] Unhandled error during server bootstrap (in storage.open)"
err.name    StorageWriterLeaseError
err.message Another Marinara Engine process (PID 45540, host MY-PC) may be using
            C:\Users\<user>\Desktop\marinara\Marinara-Engine\packages\server\data\storage.
            Close it before retrying. If it no longer exists, verify every process is
            stopped and remove only ...\packages\server\data\storage\.writer-lease.
stack
  at FileTableStore.acquireWriterLease (dist/db/file-backed-store.js:2278:23)
  at FileTableStore.initialize        (dist/db/file-backed-store.js:2383:20)
  at createFileNativeDB               (dist/db/file-backed-store.js:5192:17)
  at createStorage                    (dist/db/connection.js:10:22)
  at getDB                            (dist/db/connection.js:20:21)
  at buildApp                         (dist/app.js:134:30)

Process state at that moment (Get-Process, Get-CimInstance Win32_Process): PID 45540 did not exist; the only node.exe on the system belonged to Adobe Creative Cloud; no other Marinara, pnpm or bun process was running. start.bat's own port check had passed (otherwise it would have reopened the "existing server" instead of launching).

The lease record that blocked the start (.writer-lease/owner.json), written on 2026-10-17 by the previous server run:

{
  "version": 4,
  "pid": 45540,
  "hostId": "5d914b1b1f5420a42c3fbb67f110ce87f8740085653b2e790c4114fb2c94ea5b",
  "bootId": "2026-10-15T19:54:17.5000180Z",
  "hostname": "MY-PC",
  "token": "2dea66ac-0970-497f-9c0e-dd1dd5bce9ce",
  "acquiredAt": "2026-10-17T17:14:37.977Z"
}

After deleting the lease directory the server started, and its postmortem confirmed the previous process was killed externally:

level 40  msg "Previous session (pid 45540) ended without shutting down: last alive
2026-10-18T01:33:18.507Z after 499 min, RSS 270.2 MiB. Nothing was logged, so the
process was ended from outside - on Android/Termux the usual causes are the phantom
process killer or battery management; on desktop, a force-quit or power loss."

The lease written by the new process on 2026-10-19 — same code, but hostId: null:

{
  "version": 4,
  "pid": 8920,
  "hostId": null,
  "bootId": "2026-10-15T19:54:23.2735070Z",
  "hostname": "MY-PC",
  "token": "88a93902-cb16-45f0-8509-ef9ff975b524",
  "acquiredAt": "2026-10-19T06:29:57.632Z"
}

Additional context

  • #6674 Intermittent writer lease error persists across Marinara Engine restarts — closed 2026-09-26 asking for the exact error text and process state; the maintainer noted "Windows identity/process-start probes can also fail conservatively, but there is no evidence yet." This report supplies that evidence, and the intermittency matches: the probe succeeds on some launches and fails on others.
  • #5744 Writer lease with null hostId permanently blocks boot, fixed by #5799. That fix adds a "local-storage" same-host proof, but only when the existing lease record has hostId: null. The case here is the mirror image: the existing lease has a hostId, the current process does not.
  • #6183 / #6195 — terminal window close leaving the lease behind (different trigger, same stuck state).

Root cause analysis

References are to packages/server/src/db/file-backed-store.ts at c56501495; dist line numbers in parentheses.

  1. readStableMachineId() (win32 branch) is the first child process the module spawns, and it times out.
    CURRENT_HOST_ID (dist 1201) is evaluated before CURRENT_BOOT_ID = readBootId() (dist 1209), and nothing earlier in the module spawns a process. The probe is

    execFileSync(reg.exe, ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"],
      { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 1_000, maxBuffer: 64 * 1024, windowsHide: true })
    

    On this machine the first reg.exe call inside a Node process takes ~1.8–2.0 s and fails with ETIMEDOUT/SIGTERM; the catch returns null. A second reg.exe call in the same process takes ~40 ms. The option set is not the cause: the identical options succeed on the 2nd and 3rd call. The delay is also specific to reg.exe — a first cmd.exe /c ver in a fresh process takes ~70 ms, and reg.exe right after it still takes ~1.9 s (see Measurements). I have not determined what makes the first reg.exe invocation slow (on-access scanning by Defender is a guess, not a finding).

  2. A process whose probe timed out writes hostId: null (confirmed in the new owner.json above) and, more importantly, cannot recognise any lease that has a hostId as its own host.

  3. acquireWriterLease() (dist ~2235–2280) therefore never reaches the PID check:

    • writerLeaseBelongsToCurrentHost(record) → Boolean(CURRENT_HOST_ID && record.hostId === CURRENT_HOST_ID) → false because CURRENT_HOST_ID is null.
    • isTermuxPrivateHomeStorage(rootDir) → false on Windows.
    • The #5799 "local-storage" proof requires existing.record.hostId === null; the old record has a real hostId, so it does not apply.
    • sameHost is false, so the branch with pidDefinitelyExited(existing.record.pid) / pidWasReused(...) is skipped, staleReason stays null, and the error is thrown.
  4. Side observation — the Windows bootId is not stable. probeWindowsBootId() stores (Get-CimInstance Win32_OperatingSystem).LastBootUpTime formatted with 'o'. Without a reboot, two launches recorded ...19:54:17.5000180Z and ...19:54:23.2735070Z (~6 s apart). The "boot" staleness test compares these strings for equality, so on Windows it can report a different boot for the same boot. It did not matter in this incident (the sameHost gate failed first), but the boot-based reclaim is unreliable on win32 unless STORAGE_CACHE_WINDOWS_BOOT_ID is enabled. The comment in readBootId() already notes this probe costs 1.5–2 s and gives it timeout: 2_000; the MachineGuid probe did not get a comparable allowance.

Measurements

All runs on the machine above, Node v24.19.0, from a normal PowerShell prompt (no sandbox). GUID redacted.

A. Same execFileSync options as the engine, several variants, one process. Script:

const { execFileSync } = require("child_process"); const { join } = require("path");
const exe = join(process.env.SystemRoot, "System32", "reg.exe");
const args = ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"];
const variants = {
  "original (1s, hide, stdin ignore)": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true },
  "no timeout":                         { encoding: "utf8", stdio: ["ignore","pipe","ignore"], maxBuffer: 65536, windowsHide: true },
  "5s timeout":                         { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 5000, maxBuffer: 65536, windowsHide: true },
  "no windowsHide":                     { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536 },
  "stdin pipe":                         { encoding: "utf8", stdio: ["pipe","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true },
  "stderr pipe":                        { encoding: "utf8", stdio: ["ignore","pipe","pipe"], timeout: 1000, maxBuffer: 65536, windowsHide: true },
  "original again (last)":              { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true },
  "original 3rd":                       { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true },
};
for (const [name, opts] of Object.entries(variants)) {
  const t = Date.now();
  try {
    const out = execFileSync(exe, args, opts);
    console.log(name, "-> OK", Date.now()-t, "ms, guid:", out.match(/MachineGuid\s+REG_SZ\s+([^\r\n]+)/i)?.[1]?.trim());
  } catch (e) { console.log(name, "-> ERR", Date.now()-t, "ms", e.code, e.status, e.signal); }
}

Output (three separate processes gave the same shape; this is the third):

original (1s, hide, stdin ignore) -> ERR 1821 ms ETIMEDOUT null SIGTERM
no timeout                        -> OK   40 ms, guid: xxxxxxxx-....
5s timeout                        -> OK   39 ms, guid: xxxxxxxx-....
no windowsHide                    -> OK   16 ms, guid: xxxxxxxx-....
stdin pipe                        -> OK   39 ms, guid: xxxxxxxx-....
stderr pipe                       -> OK   39 ms, guid: xxxxxxxx-....
original again (last)             -> OK   38 ms, guid: xxxxxxxx-....
original 3rd                      -> OK   38 ms, guid: xxxxxxxx-....

The first-call failure was 1788 ms and 2020 ms in the two earlier processes; every other line was 28–53 ms.

B. Is it "first child process of any kind" or "first reg.exe"? One process, five spawns in order, 10 s timeout so nothing is cut off:

1st spawn: cmd /c ver         -> OK   68 ms
2nd spawn: reg query          -> OK 1911 ms   <- first reg.exe call, even after cmd.exe ran
3rd spawn: cmd /c ver again   -> OK   46 ms
4th spawn: reg query again    -> OK   39 ms
5th spawn: powershell boot    -> OK  931 ms   (the readBootId() probe; within its 2 s budget)

C. Baseline. reg.exe query ... MachineGuid run directly from PowerShell, three runs: 55 ms, 29 ms, 28 ms.

Takeaways: the 1 s budget is too tight for the first reg.exe call in a process on this machine, the probe runs exactly once at module load so it has no second chance, and whether it succeeds varies between launches (it did on 2026-10-17, did not on 2026-10-19) — which is the "intermittent" pattern #6674 describes.

Suggested fix

Either of the first two closes the trap; the third hardens the fallback.

  1. Give the MachineGuid probe more room: raise the timeout (e.g. 5 s, in line with the 2 s already granted to the boot-ID probe) and/or retry once on ETIMEDOUT. It runs once per process, so the cost is bounded. Alternatively defer it to the first acquireWriterLease() call instead of module load.
  2. Extend the #5799 reclaim path to the mirror case: when the current process has CURRENT_HOST_ID === null and the data directory is on machine-local storage (writerLeaseStorageIsMachineLocal), allow the same "local-storage" proof against the existing lease regardless of the existing record's hostId, so pidDefinitelyExited can run. Today that proof is granted only when the existing record has hostId: null, which leaves "old run recorded a hostId, new run could not" permanently stuck.
  3. Stabilise the Windows bootId: round LastBootUpTime to the second (or minute), or use another stable per-boot identifier, so the "boot" staleness test cannot flip for the same boot; consider enabling STORAGE_CACHE_WINDOWS_BOOT_ID by default on win32.

Workaround used: stop every Marinara process, delete packages\server\data\storage\.writer-lease, start again. I am happy to test a staging build on this machine; the first-call timeout has reproduced in every process so far.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @boricha417 on GitHub (Oct 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7801 Originally assigned to: @SpicyMarinara on GitHub. ## Summary After a force-killed server, the next start fails in `storage.open` with `StorageWriterLeaseError` naming a PID that no longer exists, and the lease is never reclaimed automatically. Root cause, measured on this machine: the win32 `readStableMachineId()` probe (`reg.exe query ... MachineGuid`, `timeout: 1_000`) intermittently times out because the **first** `reg.exe` call in a Node process takes ~1.8–2.0 s here, so the process runs with `CURRENT_HOST_ID = null` and cannot prove it is on the same host as the existing lease. This is the evidence #6674 asked for. ## Expected behavior A lease left behind by a process that no longer exists on the same machine and the same boot should be recognised as stale (the `staleReason = "pid"` path) and reclaimed without manual file deletion. ## Actual behavior Startup aborts with: ``` StorageWriterLeaseError: Another Marinara Engine process (PID 45540, host MY-PC) may be using C:\...\Marinara-Engine\packages\server\data\storage. Close it before retrying. If it no longer exists, verify every process is stopped and remove only C:\...\packages\server\data\storage\.writer-lease. ``` PID 45540 did not exist. The only way out was deleting `data/storage/.writer-lease` by hand, as the message suggests. The dead-PID check is never reached because host identification fails first (analysis below). ## Steps to reproduce 1. On a Windows machine where the first `reg.exe` call from a Node process exceeds 1 s (here: consistently ~1.8–2.0 s across 4 separate Node processes, see Measurements), run the server once at a time when the probe happens to **succeed**, so a lease with a real `hostId` exists. (On this machine that was the case on 2026-10-17; the probe is intermittent.) 2. End that server from outside (Task Manager "End task", power loss) so the lease stays behind. 3. Start the server again at a time when the probe **fails** (times out). The new process now has `CURRENT_HOST_ID = null`. Result: `StorageWriterLeaseError` on every launch until `.writer-lease` is removed manually. A deterministic variant for a test: write a v4 lease record with a non-null `hostId` and a dead PID, then start a process whose `CURRENT_HOST_ID` is `null` (e.g. make the `reg.exe` probe fail). `acquireWriterLease()` throws instead of reclaiming. ## Environment - Marinara Engine version: 2.5.0, commit `c56501495` (`main`). The previous checkout was also 2.5.0 (`7e2823696`, 2026-10-07); `git diff` between the two shows **no change** in `file-backed-store.ts` or `writer-boot-id-cache.ts`, so the same lease code produced a lease *with* a hostId on 2026-10-17 and *without* one on 2026-10-19. - Install type: source (Git checkout, `start.bat` launcher, auto-update enabled) - OS + version: Windows 11 Pro, build 10.0.26200 (x64). Node.js v24.19.0, pnpm 10.34.5 via Corepack. Antivirus: Windows Defender only (real-time protection on), no third-party AV. - Browser or app shell: N/A (the server fails before serving anything) - Data directory: `packages\server\data\storage` on the local NTFS system drive (C:) ## Logs, screenshots, or video Startup failure (pino JSON, reformatted): ``` level 50 event "startup.failed" stage "storage.open" msg "[startup] Unhandled error during server bootstrap (in storage.open)" err.name StorageWriterLeaseError err.message Another Marinara Engine process (PID 45540, host MY-PC) may be using C:\Users\<user>\Desktop\marinara\Marinara-Engine\packages\server\data\storage. Close it before retrying. If it no longer exists, verify every process is stopped and remove only ...\packages\server\data\storage\.writer-lease. stack at FileTableStore.acquireWriterLease (dist/db/file-backed-store.js:2278:23) at FileTableStore.initialize (dist/db/file-backed-store.js:2383:20) at createFileNativeDB (dist/db/file-backed-store.js:5192:17) at createStorage (dist/db/connection.js:10:22) at getDB (dist/db/connection.js:20:21) at buildApp (dist/app.js:134:30) ``` Process state at that moment (`Get-Process`, `Get-CimInstance Win32_Process`): PID 45540 did not exist; the only `node.exe` on the system belonged to Adobe Creative Cloud; no other Marinara, pnpm or bun process was running. `start.bat`'s own port check had passed (otherwise it would have reopened the "existing server" instead of launching). The lease record that blocked the start (`.writer-lease/owner.json`), written on 2026-10-17 by the previous server run: ```json { "version": 4, "pid": 45540, "hostId": "5d914b1b1f5420a42c3fbb67f110ce87f8740085653b2e790c4114fb2c94ea5b", "bootId": "2026-10-15T19:54:17.5000180Z", "hostname": "MY-PC", "token": "2dea66ac-0970-497f-9c0e-dd1dd5bce9ce", "acquiredAt": "2026-10-17T17:14:37.977Z" } ``` After deleting the lease directory the server started, and its postmortem confirmed the previous process was killed externally: ``` level 40 msg "Previous session (pid 45540) ended without shutting down: last alive 2026-10-18T01:33:18.507Z after 499 min, RSS 270.2 MiB. Nothing was logged, so the process was ended from outside - on Android/Termux the usual causes are the phantom process killer or battery management; on desktop, a force-quit or power loss." ``` The lease written by the **new** process on 2026-10-19 — same code, but `hostId: null`: ```json { "version": 4, "pid": 8920, "hostId": null, "bootId": "2026-10-15T19:54:23.2735070Z", "hostname": "MY-PC", "token": "88a93902-cb16-45f0-8509-ef9ff975b524", "acquiredAt": "2026-10-19T06:29:57.632Z" } ``` ## Additional context ### Related issues - #6674 *Intermittent writer lease error persists across Marinara Engine restarts* — closed 2026-09-26 asking for the exact error text and process state; the maintainer noted "Windows identity/process-start probes can also fail conservatively, but there is no evidence yet." This report supplies that evidence, and the intermittency matches: the probe succeeds on some launches and fails on others. - #5744 *Writer lease with null hostId permanently blocks boot*, fixed by #5799. That fix adds a "local-storage" same-host proof, but only when the **existing** lease record has `hostId: null`. The case here is the mirror image: the existing lease has a hostId, the current process does not. - #6183 / #6195 — terminal window close leaving the lease behind (different trigger, same stuck state). ### Root cause analysis References are to `packages/server/src/db/file-backed-store.ts` at `c56501495`; dist line numbers in parentheses. 1. **`readStableMachineId()` (win32 branch) is the first child process the module spawns, and it times out.** `CURRENT_HOST_ID` (dist 1201) is evaluated before `CURRENT_BOOT_ID = readBootId()` (dist 1209), and nothing earlier in the module spawns a process. The probe is ```ts execFileSync(reg.exe, ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 1_000, maxBuffer: 64 * 1024, windowsHide: true }) ``` On this machine the first `reg.exe` call inside a Node process takes ~1.8–2.0 s and fails with `ETIMEDOUT`/`SIGTERM`; the `catch` returns `null`. A second `reg.exe` call in the same process takes ~40 ms. The option set is not the cause: the identical options succeed on the 2nd and 3rd call. The delay is also specific to `reg.exe` — a first `cmd.exe /c ver` in a fresh process takes ~70 ms, and `reg.exe` right after it still takes ~1.9 s (see Measurements). I have not determined what makes the first `reg.exe` invocation slow (on-access scanning by Defender is a guess, not a finding). 2. **A process whose probe timed out writes `hostId: null`** (confirmed in the new `owner.json` above) and, more importantly, **cannot recognise any lease that has a hostId as its own host.** 3. **`acquireWriterLease()` (dist ~2235–2280) therefore never reaches the PID check:** - `writerLeaseBelongsToCurrentHost(record)` → `Boolean(CURRENT_HOST_ID && record.hostId === CURRENT_HOST_ID)` → `false` because `CURRENT_HOST_ID` is `null`. - `isTermuxPrivateHomeStorage(rootDir)` → `false` on Windows. - The #5799 "local-storage" proof requires `existing.record.hostId === null`; the old record has a real hostId, so it does not apply. - `sameHost` is `false`, so the branch with `pidDefinitelyExited(existing.record.pid)` / `pidWasReused(...)` is skipped, `staleReason` stays `null`, and the error is thrown. 4. **Side observation — the Windows `bootId` is not stable.** `probeWindowsBootId()` stores `(Get-CimInstance Win32_OperatingSystem).LastBootUpTime` formatted with `'o'`. Without a reboot, two launches recorded `...19:54:17.5000180Z` and `...19:54:23.2735070Z` (~6 s apart). The "boot" staleness test compares these strings for equality, so on Windows it can report a different boot for the same boot. It did not matter in this incident (the `sameHost` gate failed first), but the boot-based reclaim is unreliable on win32 unless `STORAGE_CACHE_WINDOWS_BOOT_ID` is enabled. The comment in `readBootId()` already notes this probe costs 1.5–2 s and gives it `timeout: 2_000`; the MachineGuid probe did not get a comparable allowance. ### Measurements All runs on the machine above, Node v24.19.0, from a normal PowerShell prompt (no sandbox). GUID redacted. **A. Same `execFileSync` options as the engine, several variants, one process.** Script: ```js const { execFileSync } = require("child_process"); const { join } = require("path"); const exe = join(process.env.SystemRoot, "System32", "reg.exe"); const args = ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"]; const variants = { "original (1s, hide, stdin ignore)": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true }, "no timeout": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], maxBuffer: 65536, windowsHide: true }, "5s timeout": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 5000, maxBuffer: 65536, windowsHide: true }, "no windowsHide": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536 }, "stdin pipe": { encoding: "utf8", stdio: ["pipe","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true }, "stderr pipe": { encoding: "utf8", stdio: ["ignore","pipe","pipe"], timeout: 1000, maxBuffer: 65536, windowsHide: true }, "original again (last)": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true }, "original 3rd": { encoding: "utf8", stdio: ["ignore","pipe","ignore"], timeout: 1000, maxBuffer: 65536, windowsHide: true }, }; for (const [name, opts] of Object.entries(variants)) { const t = Date.now(); try { const out = execFileSync(exe, args, opts); console.log(name, "-> OK", Date.now()-t, "ms, guid:", out.match(/MachineGuid\s+REG_SZ\s+([^\r\n]+)/i)?.[1]?.trim()); } catch (e) { console.log(name, "-> ERR", Date.now()-t, "ms", e.code, e.status, e.signal); } } ``` Output (three separate processes gave the same shape; this is the third): ``` original (1s, hide, stdin ignore) -> ERR 1821 ms ETIMEDOUT null SIGTERM no timeout -> OK 40 ms, guid: xxxxxxxx-.... 5s timeout -> OK 39 ms, guid: xxxxxxxx-.... no windowsHide -> OK 16 ms, guid: xxxxxxxx-.... stdin pipe -> OK 39 ms, guid: xxxxxxxx-.... stderr pipe -> OK 39 ms, guid: xxxxxxxx-.... original again (last) -> OK 38 ms, guid: xxxxxxxx-.... original 3rd -> OK 38 ms, guid: xxxxxxxx-.... ``` The first-call failure was 1788 ms and 2020 ms in the two earlier processes; every other line was 28–53 ms. **B. Is it "first child process of any kind" or "first reg.exe"?** One process, five spawns in order, 10 s timeout so nothing is cut off: ``` 1st spawn: cmd /c ver -> OK 68 ms 2nd spawn: reg query -> OK 1911 ms <- first reg.exe call, even after cmd.exe ran 3rd spawn: cmd /c ver again -> OK 46 ms 4th spawn: reg query again -> OK 39 ms 5th spawn: powershell boot -> OK 931 ms (the readBootId() probe; within its 2 s budget) ``` **C. Baseline.** `reg.exe query ... MachineGuid` run directly from PowerShell, three runs: 55 ms, 29 ms, 28 ms. Takeaways: the 1 s budget is too tight for the first `reg.exe` call in a process on this machine, the probe runs exactly once at module load so it has no second chance, and whether it succeeds varies between launches (it did on 2026-10-17, did not on 2026-10-19) — which is the "intermittent" pattern #6674 describes. ### Suggested fix Either of the first two closes the trap; the third hardens the fallback. 1. **Give the MachineGuid probe more room**: raise the timeout (e.g. 5 s, in line with the 2 s already granted to the boot-ID probe) and/or retry once on `ETIMEDOUT`. It runs once per process, so the cost is bounded. Alternatively defer it to the first `acquireWriterLease()` call instead of module load. 2. **Extend the #5799 reclaim path to the mirror case**: when the current process has `CURRENT_HOST_ID === null` and the data directory is on machine-local storage (`writerLeaseStorageIsMachineLocal`), allow the same "local-storage" proof against the existing lease **regardless of the existing record's `hostId`**, so `pidDefinitelyExited` can run. Today that proof is granted only when the *existing* record has `hostId: null`, which leaves "old run recorded a hostId, new run could not" permanently stuck. 3. **Stabilise the Windows `bootId`**: round `LastBootUpTime` to the second (or minute), or use another stable per-boot identifier, so the "boot" staleness test cannot flip for the same boot; consider enabling `STORAGE_CACHE_WINDOWS_BOOT_ID` by default on win32. Workaround used: stop every Marinara process, delete `packages\server\data\storage\.writer-lease`, start again. I am happy to test a staging build on this machine; the first-call timeout has reproduced in every process so far. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 06:14:39 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 19, 2026):

Fixed on staging by #7804. It ships in the next release; thank you for the measurements.

<!-- gh-comment-id:6265186083 --> @SpicyMarinara commented on GitHub (Oct 19, 2026): Fixed on staging by #7804. It ships in the next release; thank you for the measurements.
Author
Owner

@SpicyMarinara commented on GitHub (Oct 19, 2026):

@boricha417 thank you again for the measurements. They made this follow-up straightforward.

The two Windows cases that #7804 still left open are now handled on staging by #7812:

  • Both machine-ID checks time out, so the new run has no machine ID while the old lease recorded one.
  • An old lease written without a machine ID.

In both cases, if the data folder is on a fixed local drive and the lease was left by Marinara on this same PC, a lease whose process has exited is now reclaimed at startup. You no longer have to delete .writer-lease by hand. Network shares, mapped drives and removable drives still keep the manual step, because Marinara cannot prove that no other machine is writing there.

You offered to test a staging build on that machine. Could you give it a try? You can set Release Channel to Staging in Settings, or run git checkout staging and git pull in a git install. The case worth checking is the one from your report: end the Marinara process abruptly (for example in Task Manager) so its lease stays behind, then start it again. It should start without the manual delete, including on a launch where the first reg.exe call is slow. If it still stops, please paste the [file-storage] lines from the log.

<!-- gh-comment-id:6266745124 --> @SpicyMarinara commented on GitHub (Oct 19, 2026): @boricha417 thank you again for the measurements. They made this follow-up straightforward. The two Windows cases that #7804 still left open are now handled on `staging` by #7812: - **Both machine-ID checks time out**, so the new run has no machine ID while the old lease recorded one. - **An old lease written without a machine ID.** In both cases, if the data folder is on a fixed local drive and the lease was left by Marinara on this same PC, a lease whose process has exited is now reclaimed at startup. You no longer have to delete `.writer-lease` by hand. Network shares, mapped drives and removable drives still keep the manual step, because Marinara cannot prove that no other machine is writing there. You offered to test a staging build on that machine. Could you give it a try? You can set **Release Channel** to Staging in Settings, or run `git checkout staging` and `git pull` in a git install. The case worth checking is the one from your report: end the Marinara process abruptly (for example in Task Manager) so its lease stays behind, then start it again. It should start without the manual delete, including on a launch where the first `reg.exe` call is slow. If it still stops, please paste the `[file-storage]` lines from the log.
Author
Owner

@boricha417 commented on GitHub (Oct 21, 2026):

@SpicyMarinara Sorry for the late reply! I only noticed your comment this morning, when I updated to 2.5.1.

Thanks for the follow-up! I tested it on the same machine and everything passed.

Build: main at v2.5.1 (8042ef6ec), which already contains #7804 and #7812 (git merge-base --is-ancestor confirms both, and the 2.5.1 changelog lists them), so I tested that instead of switching to staging. Windows 11 Pro 10.0.26200, Node v24.19.0.

Setup: To keep my real data out of it, I pointed DATA_DIR at an empty test folder on the same fixed drive (C:\Users\<user>\Desktop\marinara\lease-test-data) and started the server through scripts/run-server.mjs, the same way start.bat does. "Force-kill" below is Stop-Process -Force on the PID recorded in owner.json: an abrupt termination with no shutdown handler, like ending the process in Task Manager.

# Case Result
1 Second server started on the same data folder while the first is alive Refused with StorageWriterLeaseError naming the live PID. The live writer kept its lease. ✅
2 Force-kill the server, start again (the case from my report) Started without any manual step. ✅
3 Force-kill, then rewrite the lease to hostId: null and hostname: "OTHER-PC" Stayed locked, as intended for a lease from another machine name. ✅
4 Same as 3 but with this PC's hostname (the shape of my real lease on 2026-10-19) Reclaimed through the new Windows proof. ✅
5 Normal stop with Ctrl+C .writer-lease removed on exit. ✅

Cases 3 and 4 were simulated by editing owner.json by hand after the kill, since the probe read the machine ID successfully on every server start today.

[file-storage] lines from cases 2 and 4 (hostname masked):

{"level":40,"pid":57756,"hostname":"MY-PC","previousPid":65404,"staleReason":"pid","hostProof":"host-id","msg":"[file-storage] Reclaimed the writer lease after confirming its same-host PID exited."}
{"level":40,"pid":44772,"hostname":"MY-PC","previousPid":57756,"staleReason":"pid","hostProof":"windows-local-storage","msg":"[file-storage] Reclaimed the writer lease after confirming its same-host PID exited."}

One data point on the probe itself. I ran the 2.5.1 probe logic (2 s timeout, one retry on ETIMEDOUT) in 8 fresh Node processes, so each one paid the first-reg.exe cost:

run 1: host id read | ETIMEDOUT 2011 ms -> OK 43 ms
run 2: host id read | OK 1488 ms
run 3: host id read | ETIMEDOUT 2035 ms -> OK 50 ms
run 4: host id read | OK 1872 ms
run 5: host id read | OK 1860 ms
run 6: host id read | OK 1935 ms
run 7: host id read | ETIMEDOUT 2040 ms -> OK 41 ms
run 8: host id read | OK 1719 ms

All 8 got a machine ID, but 3 of 8 needed the retry: on this machine the first reg.exe call usually takes 1.5–2.0 s, right at the 2 s budget. So the retry is doing real work here, not just covering a rare outlier. With the old 1 s budget and no retry, all 8 would have failed.

I did not reproduce "both probe attempts time out" naturally, since the retry succeeded every time. Case 4 covers the same proof from the lease side.

Thanks again, this was fun to test!

<!-- gh-comment-id:6307799050 --> @boricha417 commented on GitHub (Oct 21, 2026): @SpicyMarinara Sorry for the late reply! I only noticed your comment this morning, when I updated to 2.5.1. Thanks for the follow-up! I tested it on the same machine and everything passed. **Build:** `main` at v2.5.1 (`8042ef6ec`), which already contains #7804 and #7812 (`git merge-base --is-ancestor` confirms both, and the 2.5.1 changelog lists them), so I tested that instead of switching to `staging`. Windows 11 Pro 10.0.26200, Node v24.19.0. **Setup:** To keep my real data out of it, I pointed `DATA_DIR` at an empty test folder on the same fixed drive (`C:\Users\<user>\Desktop\marinara\lease-test-data`) and started the server through `scripts/run-server.mjs`, the same way `start.bat` does. "Force-kill" below is `Stop-Process -Force` on the PID recorded in `owner.json`: an abrupt termination with no shutdown handler, like ending the process in Task Manager. | # | Case | Result | | --- | --- | --- | | 1 | Second server started on the same data folder while the first is alive | Refused with `StorageWriterLeaseError` naming the live PID. The live writer kept its lease. ✅ | | 2 | Force-kill the server, start again (the case from my report) | Started without any manual step. ✅ | | 3 | Force-kill, then rewrite the lease to `hostId: null` and `hostname: "OTHER-PC"` | Stayed locked, as intended for a lease from another machine name. ✅ | | 4 | Same as 3 but with this PC's hostname (the shape of my real lease on 2026-10-19) | Reclaimed through the new Windows proof. ✅ | | 5 | Normal stop with Ctrl+C | `.writer-lease` removed on exit. ✅ | Cases 3 and 4 were simulated by editing `owner.json` by hand after the kill, since the probe read the machine ID successfully on every server start today. `[file-storage]` lines from cases 2 and 4 (hostname masked): ``` {"level":40,"pid":57756,"hostname":"MY-PC","previousPid":65404,"staleReason":"pid","hostProof":"host-id","msg":"[file-storage] Reclaimed the writer lease after confirming its same-host PID exited."} {"level":40,"pid":44772,"hostname":"MY-PC","previousPid":57756,"staleReason":"pid","hostProof":"windows-local-storage","msg":"[file-storage] Reclaimed the writer lease after confirming its same-host PID exited."} ``` **One data point on the probe itself.** I ran the 2.5.1 probe logic (2 s timeout, one retry on `ETIMEDOUT`) in 8 fresh Node processes, so each one paid the first-`reg.exe` cost: ``` run 1: host id read | ETIMEDOUT 2011 ms -> OK 43 ms run 2: host id read | OK 1488 ms run 3: host id read | ETIMEDOUT 2035 ms -> OK 50 ms run 4: host id read | OK 1872 ms run 5: host id read | OK 1860 ms run 6: host id read | OK 1935 ms run 7: host id read | ETIMEDOUT 2040 ms -> OK 41 ms run 8: host id read | OK 1719 ms ``` All 8 got a machine ID, but 3 of 8 needed the retry: on this machine the first `reg.exe` call usually takes 1.5–2.0 s, right at the 2 s budget. So the retry is doing real work here, not just covering a rare outlier. With the old 1 s budget and no retry, all 8 would have failed. I did not reproduce "both probe attempts time out" naturally, since the retry succeeded every time. Case 4 covers the same proof from the lease side. Thanks again, this was fun to test!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4308
No description provided.