mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5722] [MERGED] fix(storage): close two residual transaction-isolation gaps in the file-backed store #6900
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#6900
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/5722
Author: @kolacheee
Created: 9/1/2026
Status: ✅ Merged
Merged: 9/1/2026
Merged by: @kolacheee
Base:
staging← Head:fix/5651-5652-store-transaction-isolation📝 Commits (3)
e246450fix(storage): close two residual transaction-isolation gaps (#5651, #5652)5ed5f12fix(storage): close the adversarial-review findings on the isolation fixesc5903bdtest(storage): stage the isolation regression on lifecycle signals📊 Changes
3 files changed (+432 additions, -8 deletions)
View changed files
📝
CHANGELOG.md(+2 -0)📝
packages/server/src/db/file-backed-store.ts(+53 -8)➕
scripts/regressions/store-transaction-isolation.regression.ts(+377 -0)📄 Description
Linked issue
Closes #5651, closes #5652.
Why this change
The #5631 verification pass left two residual transaction-isolation gaps in the file-backed store, both silent-data bugs in narrow but reachable interleavings. #5651: reads never take the write gate, so a concurrent request can lazily load a cold chat unit mid-transaction. That load runs outside the transaction's
AsyncLocalStoragecontext, so the snapshot mirror inmergeLoadedRows(and the heal-mark mirror inrecordLoadHealMarks) never engaged — the loaded rows landed in the live table after the transaction's first-mutation snapshot, and a rollback restored the snapshot, erasing persisted rows whileloadedUnitsstill said the unit was resident. The chat stayed invisible until restart. #5652:transaction()'s opening flush wait was check-once. With two flushes parked on the sameactiveFlush(the second subscribed first), the second flush's recursion re-enters on resolve, captures the dirty set, and installs a newactiveFlushbefore the transaction's continuation resumes — which then sailed past its consumed check and ran its callback concurrently with the fresh flush's I/O.saveFileSnapshotsreads live tables, so uncommitted rows could be persisted to disk, and a rollback then left them there with no dirty mark.What changed
activeTransactionContext; the transaction queue admits at most one), and both load-effect sites resolve their target context through a sharedloadEffectTransactionContext()helper: the loader's own ALS context when present, otherwise the active transaction's. Out-of-context loads now mirror into the running transaction's snapshot and heal-mark maps exactly like in-context ones, so rollback preserves them.while (this.activeFlush) await this.activeFlush;. The recursing flush installs its newactiveFlushsynchronously before its first await, so a re-check after every wake always observes it; the transaction can no longer slip between one flush ending and the next one starting.Plus two adjacent defects in the same class, confirmed by an adversarial review of the first commit and closed here (second commit):
flush()'s own wait on active transactions was also check-once — the mirror image of #5652. A transaction queued behind the one the flush is waiting out wakes on a one-hop microtask chain while the flush's wake is two-hop, so the queued transaction activates first. ThependingTransactionFlushhandoff rescues that ordering while the store is open, but it is deliberately skipped oncewritesClosed— so during shutdown the woken flush ransaveFileSnapshotsconcurrently with the next transaction's callback and could persist uncommitted rows whose dirty marks the rollback then erased. That wait is now a loop too.snapshot.push(...mirrored)— a spread that overflows the call stack past ~100k–120k rows (eviction is off by default, so resident messages grow monotonically), and the throw landed after thelength = 0truncation, leaving an empty snapshot that a rollback would install as the live messages table. The line predates this PR, but the #5651 fix widens its reachability to every concurrent request's lazy load, so it is fixed in the same change: the merged array is built fully before the snapshot is touched, refilled with a loop.scripts/regressions/store-transaction-isolation.regression.tsreproduces all four interleavings deterministically: Parts 1–2 for #5651/#5652 (promise gates plus a one-shotbeforeTableWritemid-write hold fromFileNativeStoreTestHooks), Part 3 for the spread overflow (a 200k-row unit lazily loaded mid-transaction), Part 4 for the close-path flush overlap (an overlap detector in thebeforeTableWritehook plus an on-disk assert that a rolled-back brand-new unit leaves no shard file), with anti-vacuity asserts that the staged holds and parks actually engaged.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm lintand the server production build are green locally (re-run after the rebase onto the merged #5718/#5720 staging);format:checkfails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly).while→ifrevert → "the transaction callback must not run concurrently with the second flush's I/O"; mirror spread revert →RangeError: Maximum call stack size exceeded; flush-waitwhile→ifrevert → "a flush parked behind a transaction must not run its I/O concurrently with the next transaction's callback (close path)". Restored code passes all four parts.tx-gate-window,lazy-chat-units,message-sharding,file-backed-shutdown,storage-writer-lock.saveShardedTable's known-shard guard and the rollback's dirty-map restore).Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)CHANGELOG updated under [Unreleased] → Fixed. No user-facing docs touched, so nothing new for the
docs-i18nbatch.UI evidence (if applicable)
Not applicable — server-internal storage fix.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.