Repository navigation
fix(tauri): make temp file names collision-proof - #176
Merged
Merged
Conversation
temp_path used a millisecond-only name (fiberpath-{millis}.{ext}), so two
same-extension commands in the same millisecond (e.g. validate/preview firing
on edits, or withRetry re-firing) produced the same path — one call's
TempFile::Drop then deleted the other's file, or they clobbered each other,
causing spurious 'file not found' / corrupted output. Add the PID and a
monotonic atomic counter to the name. Test asserts 1000 rapid calls are
all unique.
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.
Bug R3 from the latent-bug audit.
Problem
temp_pathnamed filesfiberpath-{millis}.{ext}— millisecond-only entropy. Two same-extension commands landing in the same millisecond (validate/preview fire on edits;withRetrycan re-fire quickly) produced the same path, so one call'sTempFile::Dropdeleted the other's file mid-use, or they clobbered each other's contents → intermittent "file not found" / corrupted plot or validation output.Fix
Include the process id and a monotonic
AtomicU64counter in the name (fiberpath-{pid}-{millis}-{seq}.{ext}), guaranteeing uniqueness within and across processes.Test (runs in CI)
temp_path_is_unique_under_rapid_callscollects 1000 rapidtemp_pathresults into a set and asserts all 1000 are distinct — reliably fails on the old millisecond-only name (1000 calls share milliseconds), passes with the counter.