Repository navigation
Input::getAccessorUnchecked(): Wrap fetches in a path lock #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -115,3 +115,17 @@ path="$(nix flake prefetch --refresh --json "tarball+file://$TEST_ROOT/tar.tar" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $(cat "$path/a/b/xyzzy") = xyzzy ]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $(cat "$path/a/b/foo") = foo ]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $(cat "$path/bla") = abc ]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Test that concurrent invocations of Nix will fetch the tarball only once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -rf "$TEST_HOME/.cache" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| store="$TEST_ROOT/prefetch-store" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nix-store --store "$store" --init # needed because concurrent creation of the store can give SQLite errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _NIX_TEST_CONCURRENT_FETCHES=1 _NIX_FORCE_HTTP=1 nix flake prefetch --store "$store" -v "tarball+file://$TEST_ROOT/tar.tar" 2> "$TEST_ROOT/log1" & | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pid1="$!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _NIX_TEST_CONCURRENT_FETCHES=1 _NIX_FORCE_HTTP=1 nix flake prefetch --store "$store" -v "tarball+file://$TEST_ROOT/tar.tar" 2> "$TEST_ROOT/log2" & | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pid2="$!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wait "$pid1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wait "$pid2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $(cat "$TEST_ROOT/log1" "$TEST_ROOT/log2" | grep -c "Download.*to") -eq 2 ]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $(cat "$TEST_ROOT/log1" "$TEST_ROOT/log2" | grep -c "downloading.*tar.tar") -eq 1 ]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[ $(cat "$TEST_ROOT/log1" "$TEST_ROOT/log2" | grep -c "waiting for another Nix process to finish fetching input") -eq 1 ]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+119
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test does not verify process exit status before assertions. The 🛠️ Suggested fix to check exit status wait "$pid1"
+rc1=$?
wait "$pid2"
+rc2=$?
+[[ $rc1 -eq 0 ]] || { echo "First prefetch failed"; exit 1; }
+[[ $rc2 -eq 0 ]] || { echo "Second prefetch failed"; exit 1; }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lock coordination may fail across different user contexts.
getCacheDir()returns user-specific paths based onNIX_CACHE_HOME,XDG_CACHE_HOME, or~/.cache/nix. If the Nix daemon runs as root and a client runs as a regular user, they'll have different cache directories and won't see each other's locks.Per the PR description, this is intended for parallel
nix-eval-jobsinstances. If those run as the same user, this works. However, this limitation should be documented or considered if daemon-client coordination is ever expected.🤖 Prompt for AI Agents