Repository navigation
fix(state): avoid temp-file race in atomic_write_file with multiple monitors - #1813
Merged
Merged
Conversation
With more than one monitor there is one dock (and one toolbar) webview per
monitor, and each of them saves its state through `StateWriteWegItems` /
`StateWriteToolbarItems` at the same moment. Both calls ended up in
`atomic_write_file` using the same `state.yml.tmp`: the first rename moved
the file into place and the second one failed with
Unhandled Rejection Io(Os { code: 2, kind: NotFound, ... })
right after "Saving dock state" in the log. Nothing was lost (both writers
carried the same content) but the error fired on every save with two
monitors.
- Give every `atomic_write_file` call its own temporary file name
(`<name>.<pid>.<counter>.tmp`) and remove it if the rename fails.
- Hold the manager lock while writing in `WegItemsManager::write` and
`ToolbarItemsManager::write`, so in-process saves are serialized instead
of racing on the same target.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StkifHpSLWH4J5TvuP56ur
eythaann
self-requested a review
September 15, 2026 14:41
eythaann
approved these changes
Sep 15, 2026
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
With more than one monitor there is one dock (and one toolbar) webview per monitor, and each of them saves its state through
StateWriteWegItems/StateWriteToolbarItemsat the same moment. Both calls end up inatomic_write_fileusing the same temporary file (state.yml.tmp): the firstrenamemoves it into place and the second one fails withright after
Saving dock stateinSeelen UI.log. Nothing is lost, because both writers carry the same content, but the error fires on every save with two monitors (on my machine: every few seconds after a layout change, and on every startup).Fix
atomic_write_filenow uses a temporary name that is unique per call (<name>.<pid>.<counter>.tmp), and removes it if the rename fails.WegItemsManager::writeandToolbarItemsManager::writehold the manager lock while writing, so in-process saves are serialized instead of racing on the same target.Three files, no new dependencies.
Verification
I do not have a Rust toolchain on this machine, so the change has only been verified by CI (fmt, clippy, tests) on a PR against my own fork: z1pp090#2. I have not run the resulting build. The diagnosis comes from the log correlation on a two-monitor Windows 11 25H2 setup (2.8.4): the
NotFounderror appears only when both monitors logSaving dock statein the same second, and always on the second one.π€ Generated with Claude Code