[PR #5392] [MERGED] fix: recover stale storage locks after Docker container replacement #6747

Closed
opened 2026-10-23 04:13:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5392
Author: @NeoKazuya
Created: 8/22/2026
Status: ✅ Merged
Merged: 8/22/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/docker-stale-lock-recovery


📝 Commits (6)

  • a99c7c1 fix: recover stale storage locks after Docker container replacement
  • b825104 fix: make writer lease socket cleanup idempotent
  • 7b46eba test: fail when the stale socket helper exits early
  • 6ec21d5 test: require container writer liveness coverage
  • 698ccb4 fix: preserve writer lease acquisition error contract
  • 5d7aeef Merge branch 'staging' into fix/docker-stale-lock-recovery

📊 Changes

3 files changed (+277 additions, -34 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/db/file-backed-store.ts (+175 -29)
📝 scripts/regressions/storage-writer-lock.regression.ts (+101 -5)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5389

Why this change

If a container exits before shutdown cleanup finishes, it can leave Marinara's storage lock (.writer-lease) in the mounted data folder. Outside containers, the machine identity normally stays the same between starts, so Marinara can check whether the recorded process is still running. A replacement container has a new hostname and may reuse the same internal PID, so the current checks cannot confirm that the old container is gone and block the replacement on every startup.

What changed

  • In Docker and Podman, the storage lock now includes a small local socket that responds while its owner is running. If the owner exits without removing the lock, a replacement on the same host can confirm that the socket is no longer active and recover the lock.
  • Automatic recovery applies only when the replacement is on the same host and the host has not rebooted. Other cases keep the existing manual recovery path.
  • Existing lock formats and non-container installs are unchanged.
  • Extended the existing writer-lock regression to cover a live writer under a different container hostname, a stopped container that reuses the same PID, and the fallback when Marinara cannot verify that the old writer is gone.
  • Added the fix to the Unreleased changelog.

This adds one local socket while Marinara is running, with no polling or storage scan.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • pnpm check passed.
  • The focused storage writer-lock regression passed, including live-owner rejection, same-PID recovery, different-host rejection, uncertain-state rejection, existing lock formats, and clean lock removal.
  • Full pnpm test passed all 143 regressions.
  • Confirmed current staging at 57e29c8b6 still fails after a force-killed container is replaced on the same volume: the replacement had a different hostname, reused PID 13, exited with code 1, and left the old lock unchanged.
  • Built the fixed Docker image and tested it with a disposable persistent volume. After force-killing a container whose lock recorded PID 13, a replacement with a different hostname and the same PID 13 recovered the lock and served /api/health. A second live container using that volume was rejected with StorageWriterLeaseError while the replacement stayed healthy. Clean shutdown removed the lock.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG.md is updated. The existing troubleshooting steps remain valid for older locks and cases where Marinara cannot confirm that the previous process stopped.

UI evidence (if applicable)

Summary by CodeRabbit

  • Bug Fixes

    • Improved recovery of storage locks after interrupted shutdowns in recreated Docker and Podman containers.
    • Prevented replacement containers from being blocked when reusing the same internal process ID.
    • Improved detection, cleanup, and reclamation of stale storage leases, including support for legacy leases.
    • Ensured storage lease resources are cleaned up reliably during startup and shutdown.
  • Documentation

    • Added a v2.4.3 changelog entry describing these storage lock recovery improvements.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5392 **Author:** [@NeoKazuya](https://github.com/NeoKazuya) **Created:** 8/22/2026 **Status:** ✅ Merged **Merged:** 8/22/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/docker-stale-lock-recovery` --- ### 📝 Commits (6) - [`a99c7c1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a99c7c1c5298b2ab75069f2a2bcdf0b791170595) fix: recover stale storage locks after Docker container replacement - [`b825104`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b825104e18f6d7d32a7f4b82cec1c21541c29da8) fix: make writer lease socket cleanup idempotent - [`7b46eba`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7b46eba4bb012ba9f4908cdc09d00379fb6cb68b) test: fail when the stale socket helper exits early - [`6ec21d5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6ec21d56d086743dbfeee62e6626d4fc2bb5493a) test: require container writer liveness coverage - [`698ccb4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/698ccb4037b2882863ef9025e9065e3ab802c001) fix: preserve writer lease acquisition error contract - [`5d7aeef`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5d7aeef290a0c58666f9596e929dfacd5ac70c81) Merge branch 'staging' into fix/docker-stale-lock-recovery ### 📊 Changes **3 files changed** (+277 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/db/file-backed-store.ts` (+175 -29) 📝 `scripts/regressions/storage-writer-lock.regression.ts` (+101 -5) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5389 ## Why this change If a container exits before shutdown cleanup finishes, it can leave Marinara's storage lock (`.writer-lease`) in the mounted data folder. Outside containers, the machine identity normally stays the same between starts, so Marinara can check whether the recorded process is still running. A replacement container has a new hostname and may reuse the same internal PID, so the current checks cannot confirm that the old container is gone and block the replacement on every startup. ## What changed - In Docker and Podman, the storage lock now includes a small local socket that responds while its owner is running. If the owner exits without removing the lock, a replacement on the same host can confirm that the socket is no longer active and recover the lock. - Automatic recovery applies only when the replacement is on the same host and the host has not rebooted. Other cases keep the existing manual recovery path. - Existing lock formats and non-container installs are unchanged. - Extended the existing writer-lock regression to cover a live writer under a different container hostname, a stopped container that reuses the same PID, and the fallback when Marinara cannot verify that the old writer is gone. - Added the fix to the Unreleased changelog. This adds one local socket while Marinara is running, with no polling or storage scan. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passed. - The focused storage writer-lock regression passed, including live-owner rejection, same-PID recovery, different-host rejection, uncertain-state rejection, existing lock formats, and clean lock removal. - Full `pnpm test` passed all 143 regressions. - Confirmed current `staging` at `57e29c8b6` still fails after a force-killed container is replaced on the same volume: the replacement had a different hostname, reused PID 13, exited with code 1, and left the old lock unchanged. - Built the fixed Docker image and tested it with a disposable persistent volume. After force-killing a container whose lock recorded PID 13, a replacement with a different hostname and the same PID 13 recovered the lock and served `/api/health`. A second live container using that volume was rejected with `StorageWriterLeaseError` while the replacement stayed healthy. Clean shutdown removed the lock. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `CHANGELOG.md` is updated. The existing troubleshooting steps remain valid for older locks and cases where Marinara cannot confirm that the previous process stopped. ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved recovery of storage locks after interrupted shutdowns in recreated Docker and Podman containers. * Prevented replacement containers from being blocked when reusing the same internal process ID. * Improved detection, cleanup, and reclamation of stale storage leases, including support for legacy leases. * Ensured storage lease resources are cleaned up reliably during startup and shutdown. * **Documentation** * Added a v2.4.3 changelog entry describing these storage lock recovery improvements. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:13:20 +07:00
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#6747
No description provided.