-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Build failure with "failed to link or copy" on zfs on macOS #13838
Comments
Likely related to openzfsonosx/zfs#809. On macOS there is a race condition in APFS when har-linking stuff, so instead Cargo uses cargo/crates/cargo-util/src/paths.rs Lines 580 to 588 in 6087566
An solution to this specifically is a fallback to |
I don't really understand ZFS. The linked upstream openzfs issue openzfsonosx/zfs#809 (comment) might be one solution? |
Sounds related indeed.
I tried: diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs
index 743e3f3a8..01afc4d2b 100644
--- a/crates/cargo-util/src/paths.rs
+++ b/crates/cargo-util/src/paths.rs
@@ -586,7 +586,17 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
// Note that: fs::copy on macos is using CopyOnWrite (syscall fclonefileat) which should be
// as fast as hardlinking.
// See https://github.com/rust-lang/cargo/issues/10060 for the details
- fs::copy(src, dst).map(|_| ())
+ fs::copy(src, dst).map_or_else(
+ |e| {
+ tracing::debug!("copy failed {e:?}. falling back to fs::hard_link");
+
+ // Working around an issue copying too fast with zfs (probably related to
+ // https://github.com/openzfsonosx/zfs/issues/809)
+ // See https://github.com/rust-lang/cargo/issues/13838
+ fs::hard_link(src, dst)
+ },
+ |_| Ok(())
+ )
} else {
fs::hard_link(src, dst)
} and it works, should I make a PR? |
Fine with a workaround PR. Maybe we should check if the error is |
Falling back to hard_link when that happens, retrying can lead to very long wait before copying works (up to 4secs in my tests) while hard_linking works straight away. Looks related to openzfsonosx/zfs#809 Closes rust-lang#13838
Falling back to hard_link when that happens, retrying can lead to very long wait before copying works (up to 4secs in my tests) while hard_linking works straight away. Looks related to openzfsonosx/zfs#809 Closes rust-lang#13838
Workaround copying file returning EAGAIN on ZFS on mac OS ### What does this PR try to resolve? Fixes #13838 Trying to build simple hello world fail when on zfs file system on macOS fails while trying to copy files around. This PR makes cargo fallback to using hard_link when that happens, retrying can lead to very long wait before copying works (up to 4secs in my tests) while hard_linking works straight away.
Problem
Trying to build simple hello world fail when on zfs file system on macOS (it is the only problem I have found so far, building C code works and everything else seems to work)
Steps
Running
cargo build
fails with:Possible Solution(s)
No response
Notes
Version
The text was updated successfully, but these errors were encountered: