mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2319] [Issue]: No flush-on-quit — writes within the 750ms storage debounce window are lost when the app is closed #1146
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#1146
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 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2319
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — Data-loss / durability. Ordinary writes (new message, edit, swipe, settings) go through the debounced FileStorage path and sit only in the in-memory cache for up to
STORAGE_SAVE_DEBOUNCE_MS = 750msbefore reaching disk. There is no flush-on-quit anywhere insrc-tauri, and the only Drop backstop is gated onArc::strong_count == 1, which the in-flight debounce thread defeats. So quitting (or crashing) within ~750ms of the last edit silently loses that write.Expected behavior
On app shutdown the storage layer should synchronously flush all pending dirty collections to disk before the process exits, independent of
Drop/strong_counttiming.Actual behavior
write_collection(src-tauri/crates/storage/src/lib.rs:1718-1722) →cache_collection(dirty=true)+schedule_dirty_flush.schedule_dirty_flush(lib.rs:820-835) doeslet storage = self.clone();then spawns a detached thread that sleeps 750ms before flushing — holding a cache-Arc clone alive for the whole window.Drop for FileStorage(lib.rs:1954-1960) only flushes whenArc::strong_count(&self.cache) == 1; the in-flight thread's clone keeps it ≥ 2 during exactly the pending window, so Drop skips the flush.RunEvent/on_window_event/ExitRequested/WindowEvent::CloseRequestedreturns zero matches; the builder ends at.run(tauri::generate_context!())(src/lib.rs:281) with no event callback.flush()is public but only called from backup, gallery recovery, and import rollback — never on quit.On a normal Tauri window-close the underlying event loop typically exits the process without unwinding, so
Dropvery likely never runs at all — either path yields the same loss.Steps to reproduce
messages.json,settings.json) is never written; the change is gone on next launch.Impact area
Environment
b0e5561dLogs, screenshots, or video
Static source audit; cited to file:line above.
Regression notes
Found via static audit of the refactor branch; not verified against main. Loss window is bounded (~750ms, single last action) and recoverable by re-typing, hence medium.
Additional context
Suggested fix: switch to
.build(ctx)?+app.run(move |app_handle, event| { if let RunEvent::ExitRequested { .. } | RunEvent::Exit = event { if let Some(state) = app_handle.try_state::<AppState>() { let _ = state.storage.flush(); } } }).flush()already takes the write lock and callsflush_dirty_collections_locked, so it is safe from the run callback. Optionally also flush onWindowEvent::CloseRequested. Keep Drop as a secondary backstop but remove itsstrong_countblind spot.Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2379, merged into
refactor(squash2e2225cd).