dagger/dagger · error
copy file range failed
Error message
copy file range failed
What it means
This error is wrapped in fsutil/copy.CopyFileContent when the Linux copy_file_range(2) syscall fails in a way the fast path cannot tolerate. The code retries with a userspace io.CopyBuffer only when the failure is a known-recoverable errno (ENOSYS, EXDEV, EPERM, EIO, EOPNOTSUPP, EINVAL) on the first chunk; any other errno, or a recoverable errno after the first chunk, is returned wrapped as 'copy file range failed'. It signals that the kernel-assisted copy path was aborted mid-file.
Solutions
- Check that both source and destination files exist, are regular files, and are not being modified concurrently during the copy.
- Verify filesystem support: copy_file_range can fail on overlayfs/NFS/FUSE mounts; copy to a filesystem-backed temp location first, or fall back to a plain userspace copy.
- Retry the whole copy operation from scratch if a partial copy was in progress (first==false case) since a recoverable errno after the first chunk is not retried in-process.
- Update the kernel/container runtime if the errno indicates unsupported operation (ENOSYS) in containers with restricted syscalls; check seccomp profiles for copy_file_range allowlisting.
- If you control the caller, pre-check permissions (EACCES/EPERM) on both files before starting the copy.
Example fix
// before (caller, naive copy)
err := fsutil.CopyFileContent(src, dst)
// after (caller, resilient)
err := fsutil.CopyFileContent(src, dst)
if err != nil && strings.Contains(err.Error(), "copy file range failed") {
// fall back to a manual open+io.Copy
sf, serr := os.Open(src)
if serr != nil { return serr }
defer sf.Close()
df, derr := os.Create(dst)
if derr != nil { return derr }
defer df.Close()
_, err = io.Copy(df, sf)
} Defensive patterns
Strategy: fallback
Validate before calling
func canCopyFileRange(src, dst *os.File) error {
si, err := src.Stat()
if err != nil || !si.Mode().IsRegular() {
return fmt.Errorf("src not a regular file: %w", err)
}
di, err := dst.Stat()
if err != nil || !di.Mode().IsRegular() {
return fmt.Errorf("dst not a regular file: %w", err)
}
return nil
} Try / catch
err := fsutil.CopyFileContent(srcF, dstF)
if err != nil && strings.Contains(err.Error(), "copy file range failed") {
// reset file offsets and redo the copy in userspace
srcF.Seek(0, io.SeekStart); dstF.Seek(0, io.SeekStart)
_, err = io.Copy(dstF, srcF)
} Prevention
- Pre-check that both src and dst are regular files on filesystems known to support copy_file_range (ext4/xfs/btrfs, same mount).
- Copy to a temp file in the destination directory, then rename atomically, so partial-copy failures never corrupt the target.
- Check the seccomp profile of your container allows copy_file_range if running in restricted environments.
- Never mutate or truncate source files while a copy is in progress.
- Keep a userspace io.Copy fallback wired in for any caller of CopyFileContent.
When it happens
Trigger: Calling CopyFileContent (via copyFile during directory/copy operations) where unix.CopyFileRange returns an errno outside the tolerated set (e.g. EACCES, EBADF, ETXTBSY), or where a tolerated errno occurs when first==false (i.e. part of the file was already copied).
Common situations: Copying files across exotic mount points/devices where copy_file_range is partially supported (overlayfs, NFS, FUSE), source or destination file descriptors becoming invalid mid-copy, files modified/truncated concurrently during the copy, or running on kernel/container combinations with incomplete copy_file_range support.
Related errors
- failed call to UtimesNanoAt
- failed to get stat_t for %T
- expected exactly one mount, got
- failed to call utimes
- failed to chmod path
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/529c7a610d53f18d.
Report an issue: GitHub.
Appendix: source
Thrown at internal/fsutil/copy/copy_linux.go:144
}
var written int64
size := st.Size()
first := true
for written < size {
var desired int
if size-written > math.MaxInt32 {
desired = int(math.MaxInt32)
} else {
desired = int(size - written)
}
n, err := unix.CopyFileRange(int(src.Fd()), nil, int(dst.Fd()), nil, desired, 0)
if err != nil {
// matches go/src/internal/poll/copy_file_range_linux.go
if (err != unix.ENOSYS && err != unix.EXDEV && err != unix.EPERM && err != syscall.EIO && err != unix.EOPNOTSUPP && err != syscall.EINVAL) || !first {
return errors.Wrap(err, "copy file range failed")
}
buf := bufferPool.Get().(*[]byte)
_, err = io.CopyBuffer(dst, src, *buf)
bufferPool.Put(buf)
if err != nil {
return errors.Wrap(err, "userspace copy failed")
}
return nil
}
first = false
written += int64(n)
}
return nil
}
func mknod(dst string, mode uint32, rDev int) error {View on GitHub (pinned to 82ba2681db)