mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4308
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.openwithStorageWriterLeaseErrornaming a PID that no longer exists, and the lease is never reclaimed automatically. Root cause, measured on this machine: the win32readStableMachineId()probe (reg.exe query ... MachineGuid,timeout: 1_000) intermittently times out because the firstreg.execall in a Node process takes ~1.8–2.0 s here, so the process runs withCURRENT_HOST_ID = nulland 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:
PID 45540 did not exist. The only way out was deleting
data/storage/.writer-leaseby hand, as the message suggests. The dead-PID check is never reached because host identification fails first (analysis below).Steps to reproduce
reg.execall 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 realhostIdexists. (On this machine that was the case on 2026-10-17; the probe is intermittent.)CURRENT_HOST_ID = null.Result:
StorageWriterLeaseErroron every launch until.writer-leaseis removed manually.A deterministic variant for a test: write a v4 lease record with a non-null
hostIdand a dead PID, then start a process whoseCURRENT_HOST_IDisnull(e.g. make thereg.exeprobe fail).acquireWriterLease()throws instead of reclaiming.Environment
c56501495(main). The previous checkout was also 2.5.0 (7e2823696, 2026-10-07);git diffbetween the two shows no change infile-backed-store.tsorwriter-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.start.batlauncher, auto-update enabled)packages\server\data\storageon the local NTFS system drive (C:)Logs, screenshots, or video
Startup failure (pino JSON, reformatted):
Process state at that moment (
Get-Process,Get-CimInstance Win32_Process): PID 45540 did not exist; the onlynode.exeon 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:After deleting the lease directory the server started, and its postmortem confirmed the previous process was killed externally:
The lease written by the new process on 2026-10-19 — same code, but
hostId: null:Additional context
Related issues
hostId: null. The case here is the mirror image: the existing lease has a hostId, the current process does not.Root cause analysis
References are to
packages/server/src/db/file-backed-store.tsatc56501495; dist line numbers in parentheses.readStableMachineId()(win32 branch) is the first child process the module spawns, and it times out.CURRENT_HOST_ID(dist 1201) is evaluated beforeCURRENT_BOOT_ID = readBootId()(dist 1209), and nothing earlier in the module spawns a process. The probe isOn this machine the first
reg.execall inside a Node process takes ~1.8–2.0 s and fails withETIMEDOUT/SIGTERM; thecatchreturnsnull. A secondreg.execall 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 toreg.exe— a firstcmd.exe /c verin a fresh process takes ~70 ms, andreg.exeright after it still takes ~1.9 s (see Measurements). I have not determined what makes the firstreg.exeinvocation slow (on-access scanning by Defender is a guess, not a finding).A process whose probe timed out writes
hostId: null(confirmed in the newowner.jsonabove) and, more importantly, cannot recognise any lease that has a hostId as its own host.acquireWriterLease()(dist ~2235–2280) therefore never reaches the PID check:writerLeaseBelongsToCurrentHost(record)→Boolean(CURRENT_HOST_ID && record.hostId === CURRENT_HOST_ID)→falsebecauseCURRENT_HOST_IDisnull.isTermuxPrivateHomeStorage(rootDir)→falseon Windows.existing.record.hostId === null; the old record has a real hostId, so it does not apply.sameHostisfalse, so the branch withpidDefinitelyExited(existing.record.pid)/pidWasReused(...)is skipped,staleReasonstaysnull, and the error is thrown.Side observation — the Windows
bootIdis not stable.probeWindowsBootId()stores(Get-CimInstance Win32_OperatingSystem).LastBootUpTimeformatted with'o'. Without a reboot, two launches recorded...19:54:17.5000180Zand...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 (thesameHostgate failed first), but the boot-based reclaim is unreliable on win32 unlessSTORAGE_CACHE_WINDOWS_BOOT_IDis enabled. The comment inreadBootId()already notes this probe costs 1.5–2 s and gives ittimeout: 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
execFileSyncoptions as the engine, several variants, one process. Script:Output (three separate processes gave the same shape; this is the third):
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:
C. Baseline.
reg.exe query ... MachineGuidrun directly from PowerShell, three runs: 55 ms, 29 ms, 28 ms.Takeaways: the 1 s budget is too tight for the first
reg.execall 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.
ETIMEDOUT. It runs once per process, so the cost is bounded. Alternatively defer it to the firstacquireWriterLease()call instead of module load.CURRENT_HOST_ID === nulland the data directory is on machine-local storage (writerLeaseStorageIsMachineLocal), allow the same "local-storage" proof against the existing lease regardless of the existing record'shostId, sopidDefinitelyExitedcan run. Today that proof is granted only when the existing record hashostId: null, which leaves "old run recorded a hostId, new run could not" permanently stuck.bootId: roundLastBootUpTimeto the second (or minute), or use another stable per-boot identifier, so the "boot" staleness test cannot flip for the same boot; consider enablingSTORAGE_CACHE_WINDOWS_BOOT_IDby 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:
@SpicyMarinara commented on GitHub (Oct 19, 2026):
Fixed on staging by #7804. It ships in the next release; thank you for the measurements.
@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
stagingby #7812: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-leaseby 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 stagingandgit pullin 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 firstreg.execall is slow. If it still stops, please paste the[file-storage]lines from the log.@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:
mainat v2.5.1 (8042ef6ec), which already contains #7804 and #7812 (git merge-base --is-ancestorconfirms both, and the 2.5.1 changelog lists them), so I tested that instead of switching tostaging. Windows 11 Pro 10.0.26200, Node v24.19.0.Setup: To keep my real data out of it, I pointed
DATA_DIRat an empty test folder on the same fixed drive (C:\Users\<user>\Desktop\marinara\lease-test-data) and started the server throughscripts/run-server.mjs, the same waystart.batdoes. "Force-kill" below isStop-Process -Forceon the PID recorded inowner.json: an abrupt termination with no shutdown handler, like ending the process in Task Manager.StorageWriterLeaseErrornaming the live PID. The live writer kept its lease. ✅hostId: nullandhostname: "OTHER-PC".writer-leaseremoved on exit. ✅Cases 3 and 4 were simulated by editing
owner.jsonby 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):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.execost:All 8 got a machine ID, but 3 of 8 needed the retry: on this machine the first
reg.execall 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!