mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5799] [MERGED] fix(storage): reclaim stale writer leases whose writer had no machine ID #6939
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#6939
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5799
Author: @Romuromylus
Created: 9/3/2026
Status: ✅ Merged
Merged: 9/3/2026
Merged by: @Romuromylus
Base:
staging← Head:fix/writer-lease-null-host-id📝 Commits (5)
6537fd5fix(storage): reclaim stale writer leases whose writer had no machine ID8897862fix(storage): require a matching PID namespace before PID proofs under the storage-based host proof909f500docs(storage): note why a reused PID-namespace inode cannot describe a live writera19059bMerge branch 'staging' into fix/writer-lease-null-host-id134d006test(storage): guard the Linux-only writer-lock assertions for Android too📊 Changes
4 files changed (+261 additions, -10 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
docs/TROUBLESHOOTING.md(+1 -1)📝
packages/server/src/db/file-backed-store.ts(+102 -7)📝
scripts/regressions/storage-writer-lock.regression.ts(+157 -2)📄 Description
Linked issue
Closes #5744
Why this change
A file-storage writer lease whose record carries
hostId: nullcould never be reclaimed.writerLeaseBelongsToCurrentHostcompares the recorded machine ID with ours, andnullmatches no host, so none of the staleness proofs the reclaim path already trusts (earlier boot, exited PID, reused PID) were ever consulted for such a lease. Startup then failed withAnother Marinara Engine process (PID …) may be using …on every boot until someone removed.writer-leaseby hand, exactly as reported.This is not only a legacy-record problem.
hostIdcomes from/etc/machine-id(or the platform UUID / registry GUID), and the Docker image has no machine-id file, so every Docker and Podman deployment writeshostId: nullon every boot (verified on my own production container). Within one host boot the socket liveness probe from #5389 still recovers a replaced container, but after a host reboot with an unclean container shutdown (power loss, OOM kill,docker kill) the recorded scope and boot IDs no longer match, the same-host gate stays closed, and the container crash-loops forever. Native Linux hosts without/etc/machine-idhit the same wall on any crash.What changed
packages/server/src/db/file-backed-store.ts: newwriterLeaseStorageIsMachineLocal(rootDir). On Linux and Android itstatfses the storage directory and accepts it as machine-local only when the filesystem magic is on an explicit allow-list (ext2/3/4, xfs, btrfs, f2fs, zfs, bcachefs, overlayfs, tmpfs, ramfs, erofs, squashfs, ntfs, exfat, vfat, jfs). Network and cluster filesystems, FUSE mounts, unknown types, and every other platform returnfalse, which keeps today's manual-recovery behavior.acquireWriterLeasenow derives ahostProof(host-id|termux-home|local-storage). A lease withhostId: nullon machine-local storage counts as same-host, because a writer that left a lease on storage only this machine can mount necessarily ran here. The existing staleness checks (boot,liveness,pid,pid-reused) are unchanged and still gate the actual reclaim: a live unidentified writer keeps its lease, and a lease naming a different machine ID never qualifies for the storage-based proof. The reclaim warning logshostProofnext tostaleReason./proc/self/ns/pid, Linux and Android) as an optionalpidNamespacefield, and under the storage-based proof thepid/pid-reusedchecks run only when that field matches ours. A lease without it (older build, or a writer in another container) relies on the namespace-safebootandlivenessproofs alone, so a rolling restart on a custom image that lacks the liveness socket can never reclaim a still-live sibling's lease. The machine-ID and Termux proofs keep their existing PID path.FileNativeStoreTestHooks.writerLeaseStorageIsMachineLocalandwriterLeasePidNamespaceoverride the filesystem check and the recorded namespace for regressions.scripts/regressions/storage-writer-lock.regression.ts: seven new cases (exited unidentified writer in our namespace on local storage is reclaimed; unidentified writer from an earlier boot is reclaimed; live unidentified writer stays locked; exited PID from another namespace stays locked; lease without a recorded namespace stays locked; unidentified writer on shareable storage stays locked; foreign machine ID on local storage stays locked) plus realstatfsand/proc/self/ns/pidassertions on Linux. The existing Termux outside-HOME case now pins the storage proof to "shareable" so it still proves the HOME rule on its own.CHANGELOG.mdentry under Unreleased / Fixed;docs/TROUBLESHOOTING.mdgains one sentence about the automatic recovery.Out of scope, on purpose: leases with a non-null
hostIdfrom another machine (still manual, by design), Windows and macOS (they always have a stable machine ID and keep the strict path), and Docker bind mounts on virtiofs/9p such as Docker Desktop host folders (those classify as shareable and keep the manual path).One limit worth knowing, called out in the code: the filesystem check proves the filesystem type, not the block device underneath, so a non-cluster filesystem on a multi-attached block device (shared SAN LUN, multi-attach cloud volume) mounted read-write by two hosts at once is invisible to it. That setup corrupts ext4/xfs on its own and is not something the lease can protect.
The regression review also asked whether a sandboxed container runtime that fabricates a per-sandbox boot ID (gVisor, Kata, Firecracker) could let the boot-mismatch proof pre-empt the liveness probe during an overlapping rolling restart. It cannot reach the storage proof in the first place: Kata exposes volumes through virtiofs and Firecracker-class runtimes attach per-microVM block devices or NFS, neither of which is on the allow-list, and gVisor answers
statfson its gofer mounts with its own 9P magic rather than the host's. Those runtimes keep the manual-recovery path exactly as before.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
hostId: null): stopped the service cleanly, planted a v4 lease withhostId: null, PID 12, and scope/boot IDs from a fake previous boot, then started it. Onstaging(204f57fd6) the container crash-looped withStorageWriterLeaseError: Another Marinara Engine process (PID 12, host deadbeefcafe) may be using /app/data/storageon every restart until I removed.writer-leaseby hand.[file-storage] Reclaimed the writer lease after detecting that the previous owner belonged to an earlier boot.withstaleReason: "boot", hostProof: "local-storage", and wrote a fresh lease. A clean stop/start afterwards still releases and re-acquires normally.hostId: null) lease, and it correctly refused with the "may be using" error until the old writer shut down, then acquired on retry. A live unidentified writer is still protected.pnpm checkpasses locally.node ./scripts/run-regressions.mjs --filter scripts/regressions/storage-writer-lock.regression.tspasses on Windows (hook-driven cases plus the "storage proof is limited to Linux and Android" assertion); the Linuxstatfsassertion runs in CI.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation): follow-up #5800UI evidence (if applicable)
Server-only change; no UI.
Summary by CodeRabbit
Bug Fixes
Documentation
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.