kopia/kopia · error
could not create CPU profile output file
Error message
could not create CPU profile output file
What it means
During kopia's profiling start (cli/profile.go), the CPU profiler output file <profDir>/cpu.pprof is created with os.Create; when that fails the error is wrapped as "could not create CPU profile output file". This means the process could not open the file for writing in the configured profile directory.
Solutions
- Create the profile directory first (mkdir -p <profDir>) and verify it exists.
- Ensure the user running kopia has write permission on the profile directory.
- Free disk space or fix an invalid path passed via the profiling flag.
- Disable CPU profiling if you don't need it.
Example fix
// before kopia --profile-cpu --profile-directory /nonexistent-dir server start // after mkdir -p /var/tmp/kopia-profiles kopia --profile-cpu --profile-directory /var/tmp/kopia-profiles server start
Defensive patterns
Strategy: validation
Validate before calling
profDir := flagProfileDirectory
if info, err := os.Stat(profDir); err != nil || !info.IsDir() {
os.MkdirAll(profDir, 0o755)
}
if f, err := os.CreateTemp(profDir, ".write-test"); err != nil {
// directory not writable: fix permissions/path before enabling profiling
} else {
f.Close(); os.Remove(f.Name())
} Try / catch
if err := runKopia(args); err != nil {
if strings.Contains(err.Error(), "could not create CPU profile output file") {
// retry without profiling flags or with a writable profDir
}
} Prevention
- mkdir -p the profile directory before enabling CPU profiling.
- Ensure the kopia user owns or can write to the profile directory.
- Watch for read-only container filesystems and disk-full alerts.
- Enable profiling flags only when actually diagnosing performance.
When it happens
Trigger: Running kopia with CPU profiling enabled (--profile-cpu or equivalent) where os.Create(profDir/cpu.pprof) fails because the directory does not exist, is not writable, disk is full, or the path is invalid.
Common situations: Pointing the profile directory at a read-only filesystem or a path owned by another user; running in a container with a read-only root filesystem; disk-full conditions; typos in the --profile-directory flag or a stale path after a volume remount.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- can't change file times
- can't create tmp file
- can't get local fs entry
- cannot create directory
- cannot create parent directory for temp file
AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07).
Data as JSON: /api/errors/73ee911f47ae05a8.
Report an issue: GitHub.
Appendix: source
Thrown at cli/profile.go:91
return nil
}
c.outputDirectory = outputDirectory
// ensure upfront that the pprof output dir can be created.
profDir, err := mkSubdirectories(c.outputDirectory, profDirName)
if err != nil {
return err
}
if !c.profileCPU {
return nil
}
// start CPU profile dumper
f, err := os.Create(filepath.Join(profDir, "cpu.pprof")) //nolint:gosec
if err != nil {
return errors.Wrap(err, "could not create CPU profile output file")
}
// CPU profile closer
closer := func() {
pprof.StopCPUProfile()
if err := f.Close(); err != nil {
log(ctx).Warn("error closing CPU profile output file:", err)
}
}
if err := pprof.StartCPUProfile(f); err != nil {
closer()
return errors.Wrap(err, "could not start CPU profile")
}
c.cpuProfileCloser = closerView on GitHub (pinned to 82495e54b5)