Skip to content
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

Closed
thiblahute opened this issue May 1, 2024 · 4 comments · Fixed by #13845
Closed

Build failure with "failed to link or copy" on zfs on macOS #13838

thiblahute opened this issue May 1, 2024 · 4 comments · Fixed by #13845
Labels
A-filesystem Area: issues with filesystems C-bug Category: bug O-macos OS: macOS S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@thiblahute
Copy link
Contributor

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:

Compiling hello_cargo v0.1.0 (/Volumes/data/devel/misc/hello_cargo)                                                                                                                                   
error: failed to link or copy `/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03` to `/Volumes/data/devel/misc/hello_cargo/target/debug/hello_cargo`                   │

Caused by:                                                                                                                                                                                             
  Resource temporarily unavailable (os error 35)  

Possible Solution(s)

No response

Notes

$ RUSTC_LOG=debug CARGO_LOG=debug cargo build --verbose
    ... 
┐rustc_trait_selection::traits::fully_normalize 
├─┐rustc_trait_selection::traits::project::normalize_with_depth_to depth=0, value=[]
├─┘
┘
┐rustc_infer::infer::lexical_region_resolve::collect_errors 
┘
INFO rustc_codegen_ssa::base codegen_instance(<fn() as FnOnce<()>>::call_once - shim(fn()))
INFO rustc_codegen_ssa::base codegen_instance(std::ptr::drop_in_place::<{closure@rt::lang_start<()>::{closure#0}}> - shim(None))
INFO rustc_interface::passes Post-codegen
Ty interner             total           ty lt ct all
    Adt               :     56 12.9%,  0.0%   2.3%  0.0%  0.0%
    Array             :     16  3.7%,  0.0%   2.1%  0.0%  0.0%
    Slice             :     14  3.2%,  0.0%   1.4%  0.0%  0.0%
    RawPtr            :     11  2.5%,  0.0%   0.0%  0.0%  0.0%
    Ref               :    124 28.6%,  2.3%  11.1%  0.0%  0.0%
    FnDef             :     39  9.0%,  0.0%   1.4%  0.5%  0.0%
    FnPtr             :      6  1.4%,  0.0%   0.0%  0.0%  0.0%
    Placeholder       :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Coroutine         :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    CoroutineWitness  :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Dynamic           :      9  2.1%,  0.0%   0.0%  0.0%  0.0%
    Closure           :      2  0.5%,  0.0%   0.0%  0.0%  0.0%
    Tuple             :      4  0.9%,  0.0%   0.0%  0.0%  0.0%
    Bound             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Param             :     11  2.5%,  0.0%   0.0%  0.0%  0.0%
    Infer             :    126 29.1%, 23.1%   0.0%  0.0%  0.0%
    Alias             :     13  3.0%,  0.0%   0.0%  0.0%  0.0%
    Foreign           :      2  0.5%,  0.0%   0.0%  0.0%  0.0%
                  total    433        25.4%  18.2%  0.5%  0.0%
GenericArgs interner: #155
Region interner: #565
Const Allocation interner: #23
Layout interner: #46

INFO rustc_codegen_ssa::back::link preparing Executable to "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03"
INFO rustc_codegen_ssa::back::link env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/thiblahute/bin:/Users/thiblahute/.nvm/versions/node/v22.0.0/bin:/Users/thiblahute/bin/google-cloud-sdk/bin:/Users/thiblahute/Library/Python/3.9/bin:/Users/thiblahute/bin:/Users/thiblahute/.depot/bin:/Users/thiblahute/.npm-global/bin:/Users/thiblahute/bin/my-devtools:/opt/homebrew/Cellar/m4/1.4.19/bin:/Users/thiblahute/bin:/Users/thiblahute/bin/google-cloud-sdk/bin:/Users/thiblahute/Library/Python/3.9/bin:/Users/thiblahute/bin:/Users/thiblahute/.depot/bin:/Users/thiblahute/.npm-global/bin:/Users/thiblahute/bin/my-devtools:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/go/bin:/usr/local/zfs/bin:/Users/thiblahute/.cargo/bin:/usr/lib/ccache/bin/:/usr/lib/icecream/bin:/Users/thiblahute/.cargo/bin:/Users/thiblahute/bin/git-phab/:/Users/thiblahute/bin/git-bz/:/Users/thiblahute/bin/git-archive-all.sh/:/Users/thiblahute/bin/:/Users/thiblahute/.local/go/bin:/Users/thiblahute/.local/bin:/Users/thiblahute/bin/patman/:/Users/thiblahute/devel/gstreamer/gst-build/meson/:/Users/thiblahute/devel/misc/depot_tools:/home/thiblahute/devel/gstreamer/gst-build/gst-devtools/debug-viewer:/Users/thiblahute/bin/allure/bin:/Users/thiblahute/.poetry/bin:/Users/thiblahute/.local/share/flatpak/exports/bin/:/usr/local/go/bin:/usr/lib/ccache/bin/:/usr/lib/icecream/bin:/Users/thiblahute/.cargo/bin:/Users/thiblahute/bin/git-phab/:/Users/thiblahute/bin/git-bz/:/Users/thiblahute/bin/git-archive-all.sh/:/Users/thiblahute/bin/:/Users/thiblahute/.local/go/bin:/Users/thiblahute/.local/bin:/Users/thiblahute/bin/patman/:/Users/thiblahute/devel/gstreamer/gst-build/meson/:/Users/thiblahute/devel/misc/depot_tools:/home/thiblahute/devel/gstreamer/gst-build/gst-devtools/debug-viewer:/Users/thiblahute/bin/allure/bin:/Users/thiblahute/.poetry/bin:/Users/thiblahute/.local/share/flatpak/exports/bin/:/usr/local/go/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/9w/s7tm2hnn7y7d_jv5q_pn8mkc0000gn/T/rustcs7SIV2/symbols.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.11drbqbabi6r1aby.rcgu.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.33uv80zlv7467gp8.rcgu.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.4k69ddrwc5z0q1d2.rcgu.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.4sxfbg7j9eyn4zya.rcgu.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.4x6hnecg7c2uuy6j.rcgu.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.52txyyh7rnmo5hfp.rcgu.o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03.23kz3x8k4fjdx1p3.rcgu.o" "-L" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps" "-L" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-b7bbc4a3799f91ec.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-9a832f29e113f2ac.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-187acb73fb221979.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f379d77720ea5d52.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-5f995b6402184362.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-6d4646231255d040.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ddf92ea3297b7931.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-4bd9fc9ff7289783.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-bbf01e0821f9af8a.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-df3ad4119d36f143.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-3839cef552c2783c.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-130a17e70576817a.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f7bc4dcd41ebfabc.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-3b8c9f0215d4bce7.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-8e6430dafe1e0d1f.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-9d92a40a452d227c.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-fb23eb00feddf1cb.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-c6577f5d4f5dcd9a.rlib" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-6d556b0e8bf6f23e.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/thiblahute/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03" "-Wl,-dead_strip" "-nodefaultlibs"
INFO rustc_codegen_ssa::back::link linker stderr:

INFO rustc_codegen_ssa::back::link linker stdout:

   0.185422583s DEBUG cargo_util::paths: set file mtime /Volumes/data/devel/misc/hello_cargo/target/debug/.fingerprint/hello_cargo-b15663378fbcff03/dep-bin-hello_cargo to 1714582167.625250491s
   0.185465792s DEBUG cargo_util::paths: linking /Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03 to /Volumes/data/devel/misc/hello_cargo/target/debug/hello_cargo
   0.185581083s DEBUG cargo_util::paths: link failed Resource temporarily unavailable (os error 35). falling back to fs::copy
   0.185701875s DEBUG cargo::core::compiler::job_queue: end (Unit { pkg: Package { id: PackageId { name: "hello_cargo", version: "0.1.0", source: "/Volumes/data/devel/misc/hello_cargo" }, ..: ".." }, target: TargetInner { name: "hello_cargo", doc: true, ..: with_path("/Volumes/data/devel/misc/hello_cargo/src/main.rs", Edition2021) }, profile: Profile { split_debuginfo: Some("unpacked"), ..: default_dev() }, kind: Host, mode: Build, features: [], artifact: false, artifact_target_for_features: None, is_std: false, dep_hash: 2202906307356721367 }): Err(failed to link or copy `/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03` to `/Volumes/data/devel/misc/hello_cargo/target/debug/hello_cargo`

Caused by:
    Resource temporarily unavailable (os error 35)

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: <core::result::Result<(), std::io::error::Error> as anyhow::Context<(), std::io::error::Error>>::with_context::<alloc::string::String, cargo_util::paths::_link_or_copy::{closure#3}>
   2: cargo_util::paths::_link_or_copy
   3: <cargo::core::compiler::link_targets::{closure#1} as core::ops::function::FnOnce<(&cargo::core::compiler::job_queue::job_state::JobState,)>>::call_once::{shim:vtable#0}
   4: <<cargo::core::compiler::job_queue::job::Work>::then::{closure#0} as core::ops::function::FnOnce<(&cargo::core::compiler::job_queue::job_state::JobState,)>>::call_once::{shim:vtable#0}
   5: <<cargo::core::compiler::job_queue::job::Work>::then::{closure#0} as core::ops::function::FnOnce<(&cargo::core::compiler::job_queue::job_state::JobState,)>>::call_once::{shim:vtable#0}
   6: <cargo::core::compiler::job_queue::job::Job>::run
   7: <cargo::core::compiler::job_queue::job_state::JobState>::run_to_finish
   8: std::sys_common::backtrace::__rust_begin_short_backtrace::<<cargo::core::compiler::job_queue::DrainState>::run::{closure#1}, ()>
   9: <<std::thread::Builder>::spawn_unchecked_<<cargo::core::compiler::job_queue::DrainState>::run::{closure#1}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  10: std::sys::pal::unix::thread::Thread::new::thread_start
  11: __pthread_joiner_wake)
   0.185911583s DEBUG cargo: display_error; err=failed to link or copy `/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03` to `/Volumes/data/devel/misc/hello_cargo/target/debug/hello_cargo`

Caused by:
    Resource temporarily unavailable (os error 35)

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: <core::result::Result<(), std::io::error::Error> as anyhow::Context<(), std::io::error::Error>>::with_context::<alloc::string::String, cargo_util::paths::_link_or_copy::{closure#3}>
   2: cargo_util::paths::_link_or_copy
   3: <cargo::core::compiler::link_targets::{closure#1} as core::ops::function::FnOnce<(&cargo::core::compiler::job_queue::job_state::JobState,)>>::call_once::{shim:vtable#0}
   4: <<cargo::core::compiler::job_queue::job::Work>::then::{closure#0} as core::ops::function::FnOnce<(&cargo::core::compiler::job_queue::job_state::JobState,)>>::call_once::{shim:vtable#0}
   5: <<cargo::core::compiler::job_queue::job::Work>::then::{closure#0} as core::ops::function::FnOnce<(&cargo::core::compiler::job_queue::job_state::JobState,)>>::call_once::{shim:vtable#0}
   6: <cargo::core::compiler::job_queue::job::Job>::run
   7: <cargo::core::compiler::job_queue::job_state::JobState>::run_to_finish
   8: std::sys_common::backtrace::__rust_begin_short_backtrace::<<cargo::core::compiler::job_queue::DrainState>::run::{closure#1}, ()>
   9: <<std::thread::Builder>::spawn_unchecked_<<cargo::core::compiler::job_queue::DrainState>::run::{closure#1}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  10: std::sys::pal::unix::thread::Thread::new::thread_start
  11: __pthread_joiner_wake
error: failed to link or copy `/Volumes/data/devel/misc/hello_cargo/target/debug/deps/hello_cargo-b15663378fbcff03` to `/Volumes/data/devel/misc/hello_cargo/target/debug/hello_cargo`

Caused by:
  Resource temporarily unavailable (os error 35)
   0.186169792s  INFO cargo::util::rustc: updated rustc info cache
   0.186205875s DEBUG cargo: exit_with_error; err=CliError { error: Some(1 job failed

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: <anyhow::Error>::new::<cargo::util::errors::AlreadyPrintedError>
   2: <cargo::core::compiler::job_queue::DrainState>::drain_the_queue
   3: std::panicking::try::<core::result::Result<(), anyhow::Error>, core::panic::unwind_safe::AssertUnwindSafe<std::thread::scoped::scope<<cargo::core::compiler::job_queue::JobQueue>::execute::{closure#3}, core::result::Result<(), anyhow::Error>>::{closure#0}>>
   4: std::thread::scoped::scope::<<cargo::core::compiler::job_queue::JobQueue>::execute::{closure#3}, core::result::Result<(), anyhow::Error>>
   5: <cargo::core::compiler::job_queue::JobQueue>::execute
   6: <cargo::core::compiler::context::Context>::compile
   7: cargo::ops::cargo_compile::compile_ws
   8: cargo::ops::cargo_compile::compile
   9: cargo::commands::build::exec
  10: cargo::cli::main
  11: cargo::main
  12: std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  13: std::rt::lang_start::<()>::{closure#0}
  14: std::rt::lang_start_internal
  15: _main), exit_code: 101 }
   0.186262250s DEBUG cargo: display_error; err=1 job failed

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: <anyhow::Error>::new::<cargo::util::errors::AlreadyPrintedError>
   2: <cargo::core::compiler::job_queue::DrainState>::drain_the_queue
   3: std::panicking::try::<core::result::Result<(), anyhow::Error>, core::panic::unwind_safe::AssertUnwindSafe<std::thread::scoped::scope<<cargo::core::compiler::job_queue::JobQueue>::execute::{closure#3}, core::result::Result<(), anyhow::Error>>::{closure#0}>>
   4: std::thread::scoped::scope::<<cargo::core::compiler::job_queue::JobQueue>::execute::{closure#3}, core::result::Result<(), anyhow::Error>>
   5: <cargo::core::compiler::job_queue::JobQueue>::execute
   6: <cargo::core::compiler::context::Context>::compile
   7: cargo::ops::cargo_compile::compile_ws
   8: cargo::ops::cargo_compile::compile
   9: cargo::commands::build::exec
  10: cargo::cli::main
  11: cargo::main
  12: std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  13: std::rt::lang_start::<()>::{closure#0}
  14: std::rt::lang_start_internal
  15: _main

Version

cargo 1.77.2 (e52e36006 2024-03-26)
release: 1.77.2
commit-hash: e52e360061cacbbeac79f7f1215a7a90b6f08442
commit-date: 2024-03-26
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.4.0 (sys:0.4.70+curl-8.5.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.4.1 [64-bit]
@thiblahute thiblahute added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels May 1, 2024
@weihanglo
Copy link
Member

Likely related to openzfsonosx/zfs#809.

On macOS there is a race condition in APFS when har-linking stuff, so instead Cargo uses fs::copy.

if cfg!(target_os = "macos") {
// This is a work-around for a bug on macos. There seems to be a race condition
// with APFS when hard-linking binaries. Gatekeeper does not have signing or
// hash information stored in kernel when running the process. Therefore killing it.
// This problem does not appear when copying files as kernel has time to process it.
// 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(|_| ())

An solution to this specifically is a fallback to fs::hard_link again on macOS. I don't quite sure if it works since I don't have ZFS on macOS nearby to test.

@weihanglo weihanglo added O-macos OS: macOS A-filesystem Area: issues with filesystems S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. labels May 1, 2024
@weihanglo
Copy link
Member

I don't really understand ZFS. The linked upstream openzfs issue openzfsonosx/zfs#809 (comment) might be one solution?

@thiblahute
Copy link
Contributor Author

thiblahute commented May 1, 2024

Likely related to openzfsonosx/zfs#809.

Sounds related indeed.

On macOS there is a race condition in APFS when har-linking stuff, so instead Cargo uses fs::copy.

if cfg!(target_os = "macos") {
// This is a work-around for a bug on macos. There seems to be a race condition
// with APFS when hard-linking binaries. Gatekeeper does not have signing or
// hash information stored in kernel when running the process. Therefore killing it.
// This problem does not appear when copying files as kernel has time to process it.
// 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(|_| ())

An solution to this specifically is a fallback to fs::hard_link again on macOS. I don't quite sure if it works since I don't have ZFS on macOS nearby to test.

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?

@weihanglo
Copy link
Member

Fine with a workaround PR. Maybe we should check if the error is EAGAIN (errno 35)?

thiblahute added a commit to thiblahute/cargo that referenced this issue May 2, 2024
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
thiblahute added a commit to thiblahute/cargo that referenced this issue May 2, 2024
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
bors added a commit that referenced this issue May 2, 2024
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.
@bors bors closed this as completed in defff44 May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-filesystem Area: issues with filesystems C-bug Category: bug O-macos OS: macOS S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants