Repository navigation
fix(cache): give each compose-config write its own temp file (BDS-133) - #93
Merged
Merged
Conversation
__xcind-write-compose-config always wrote to "${dest}.tmp". Two concurrent
xcind commands for the same app and cache SHA therefore shared one temp
path: both opened it, the first renamed it into place, and the second
failed with "mv: cannot stat ... resolved-config.yaml.tmp". The second
writer also kept writing through its open descriptor after the rename,
which defeated the atomic-write guarantee and could expose partial content.
Use mktemp in the destination directory instead, matching
__xcind-write-cache-file and __xcind-write-cache-config-json. The rename
stays atomic on one filesystem, concurrent writers complete independently,
and the last one to finish wins.
The regression test re-enters the function from inside the docker stub, so
two writes overlap deterministically with no timing dependency.
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.
Closes BDS-133.
Problem
__xcind-write-compose-configalways wrote to${dest}.tmp. Two concurrent xcind commands for the same application and cache SHA shared that one path:resolved-config.yaml.tmp.Process B fails with
mv: cannot stat '.../resolved-config.yaml.tmp': No such file or directory. Process B also keeps writing through its open descriptor after the rename, so it can modify the artifact another process already published. That behavior defeats the atomic-write guarantee and can expose incomplete content.Change
Create the temp file with
mktempin the destination directory, one per call. Rename it only after Docker Compose succeeds, and remove it on any error.The rename stays atomic, because the temp file and the destination sit on one filesystem. Concurrent writers complete independently. The last writer to finish wins.
This matches the pattern
__xcind-write-cache-fileand__xcind-write-cache-config-jsonalready use.Test
The regression test re-enters
__xcind-write-compose-configfor the same destination from inside thedockerstub, while the outer call's temp file is still open. Two writes therefore overlap inside one process, with no timing dependency and no flakiness.Verified against the pre-fix code: the test reproduces the exact error from the issue. It covers four things.
make checkpasses with zero failures.Out of scope
__xcind-run-hooksremoves and rebuilds one shared generated-hook directory without a lock. That is a separate concurrency risk. It needs a per-SHA lock around the full prepare pipeline, which carries different risk, so it belongs in its own issue.