Repository navigation
fix(persistence): serialize atomic file writes per path - #143
Merged
Merged
Conversation
writeFileAtomically reused a fixed `$path.tmp` and its debounce timer was fire-and-forget, so two flushes for the same path could overlap whenever a write was slow. The second flush then deleted or renamed the temp file the first was still using, throwing unhandled PathNotFoundException (`Cannot rename/delete file`) and silently losing the write. Serialize flushes per path through a write chain, and treat persistence as best-effort so a transient I/O failure neither surfaces as an unhandled async error nor breaks later writes. Add a contract test covering coalescing, last-write-wins and temp-file cleanup.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The debug log attached to #128 contains six unhandled
PathNotFoundExceptions while persisting shell state, e.g.:(The same failure hit
WindowManager.jsonand the workspace files.)Root cause
writeFileAtomicallywrote through a fixed temp name ($path.tmp) and its debounce timer was fire-and-forget. When a write was slow enough that the debounce fired again while the first flush was still in flight, the second flush deleted and renamed the temp file the first was still using — henceCannot rename/delete file. Because the cache (_latestFileContents) was updated before the write, a failed write also made later identical writes look like no-ops, so state silently stopped persisting.Fix
$path.tmpis safe.Tests
test/write_file_atomically_test.dart: coalescing + last-write-wins + no leftover.tmp, and a burst across several debounce windows asserts no unhandled errors and the final content.flutter analyzeclean,flutter testgreen,cargo checkgreen.Refs #128.