ipfs/kubo · warning
copying binary %q: %w
Error message
copying binary %q: %w
What it means
binary() copies the executable bytes into the profile archive with io.Copy(w, fi), closes the file, and wraps any copy error as "copying binary %q" with the path. Collection already succeeded in finding and opening the binary; the failure happened while streaming its bytes into the destination writer.
Source
Thrown at profile/profile.go:242
err error
)
if goos == "linux" {
pid := os.Getpid()
path = fmt.Sprintf("/proc/%d/exe", pid)
} else {
path, err = os.Executable()
if err != nil {
return fmt.Errorf("finding binary path: %w", err)
}
}
fi, err := os.Open(path)
if err != nil {
return fmt.Errorf("opening binary %q: %w", path, err)
}
_, err = io.Copy(w, fi)
_ = fi.Close()
if err != nil {
return fmt.Errorf("copying binary %q: %w", path, err)
}
return nil
}
func mutexProfile(ctx context.Context, opts Options, w io.Writer) error {
prev := runtime.SetMutexProfileFraction(opts.MutexProfileFraction)
defer runtime.SetMutexProfileFraction(prev)
err := waitOrCancel(ctx, opts.ProfileDuration)
if err != nil {
return err
}
return pprof.Lookup("mutex").WriteTo(w, 2)
}
func blockProfile(ctx context.Context, opts Options, w io.Writer) error {
runtime.SetBlockProfileRate(int(opts.BlockProfileRate.Nanoseconds()))
defer runtime.SetBlockProfileRate(0)
err := waitOrCancel(ctx, opts.ProfileDuration)View on GitHub (pinned to 329838acdf)
Solutions
- Read the wrapped path and inner error to find whether read or write side failed
- Check disk space on the archive destination before embedding large binaries
- Never mutate/delete the running binary while profiling (serialize upgrade and profile collection)
- Consider excluding the binary collector for very large executables if archives are size-constrained
Defensive patterns
Strategy: try-catch
Validate before calling
if st, err := os.Stat(binPath); err != nil || st.Size() > maxEmbedSize {
return skipBinaryCollector
} Try / catch
if err := WriteProfiles(ctx, p); err != nil {
if strings.HasPrefix(err.Error(), "copying binary") {
log.Printf("binary copy failed mid-stream (%v); retry without concurrent upgrade", errors.Unwrap(err))
}
return err
} Prevention
- Serialize binary upgrades and profile collection so the image never changes mid-read
- Ensure enough free space for an archive that includes the full executable
- Check filesystem health if EIO appears during reads
- Skip binary embedding for very large executables or size-limited archives
When it happens
Trigger: io.Copy(w, fi) fails: the destination writer w (the profile buffer feeding the archive) hit an underlying write error, the binary file shrank/vanished mid-read (upgrade race), read() returned EIO on a damaged filesystem, or large binaries hit a size limit on the output.
Common situations: Disk filling up while a multi-hundred-MB binary is being embedded; concurrent self-upgrade truncating the executable during read; reading from a flaky network/overlay filesystem inside containers.
Related errors
- opening binary %q: %w
- unexpected error while checking writeablility of repo root:
- flushing %s: %w
- copying binary to stash: %w
- syncing stash file: %w
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/1e704113bb60c119.
Report an issue: GitHub.