mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2527] [Issue]: In-app updater exits without flushing the file-backed store (data loss) #1255
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#1255
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 @Romuromylus on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2527
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — data loss. The in-app updater exits via
process.exit(0)without flushing the file-backed store, so any writes still in the 750 ms debounce window (or awaiting the 10 s safety flush) are silently lost when a user applies an update. The graceful shutdown path flushes correctly; the updater bypasses it.Expected behavior
Before exiting, the "Apply update" route should perform the same durable flush the graceful shutdown path uses —
await flushDB()(orawait app.close()so theonClosehooks run) — so no pending writes are dropped.Actual behavior
packages/server/src/routes/updates.routes.ts:702-705:The store is a debounced write-back cache:
markDirty()arms a 750 ms debounce (SAVE_DEBOUNCE_MS) and a 10 s safety interval (SAFETY_SAVE_MS) beforeflush()touches disk (file-backed-store.ts). Durable flushes happen only via the graceful path (SIGTERM/SIGINT→shutdown()→app.close()→ FastifyonCloseatapp.ts:75-83→closeDB()→fileStore.close()→flush(true)) or an explicitflushDB().process.exit(0)runs neither — Node does not execute FastifyonClosehooks on an explicit exit, and thebeforeExitautosave handler does not fire onprocess.exit(). The 500 ms timer is shorter than the 750 ms debounce, so a write landing during the install/rebuild step (an autonomous agent turn, an in-progress user message persist, a swipe patch) is dropped. NoflushDB()/closeDB()/app.close()appears anywhere inupdates.routes.ts.Steps to reproduce
process.exit(0); the unflushed dirty tables (messages.json,chats.json,game_state_snapshots.json, etc.) never reach disk and the writes are lost after relaunch.Environment
staging @ a9fdae8)Logs, screenshots, or video
Static source audit, cited to file:line above.
Additional context
Fix: before
process.exit(0),await flushDB()(import { flushDB } from "../db/connection.js"), or betterawait app.close()/closeDB()so theonClosehooks, sidecar stop, and the durableflush(true)all run — mirroringindex.tsshutdown().flushDB()is the in-repo reference pattern, already used inbackup.routes.ts:678/1585/1637before reading storage files.This is bounded to the rare, user-initiated update event (not an every-turn path), hence Medium.
Regression notes: found via static audit; the identical no-flush
process.exit(0)exists onmain(65a0395,updates.routes.ts:704), so this is a long-standing shared bug, not amain→stagingregression.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@Romuromylus commented on GitHub (Jun 9, 2026):
Related to #2528 — both concern the file-backed store. This one is the missing durable flush on the updater exit path; #2528 is the synchronous cost of each flush that does fire. A fix here (await
flushDB()/app.close()beforeprocess.exit(0)) and the async-flush change in #2528 touch the sameflush()/atomicWriteFilemachinery, so they're worth handling together.