{"record":{"id":"73ee911f47ae05a8","repo":"kopia/kopia","slug":"could-not-create-cpu-profile-output-file","errorCode":null,"errorMessage":"could not create CPU profile output file","messagePattern":"could not create CPU profile output file","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/profile.go","lineNumber":91,"sourceCode":"\t\treturn nil\n\t}\n\n\tc.outputDirectory = outputDirectory\n\n\t// ensure upfront that the pprof output dir can be created.\n\tprofDir, err := mkSubdirectories(c.outputDirectory, profDirName)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !c.profileCPU {\n\t\treturn nil\n\t}\n\n\t// start CPU profile dumper\n\tf, err := os.Create(filepath.Join(profDir, \"cpu.pprof\")) //nolint:gosec\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"could not create CPU profile output file\")\n\t}\n\n\t// CPU profile closer\n\tcloser := func() {\n\t\tpprof.StopCPUProfile()\n\n\t\tif err := f.Close(); err != nil {\n\t\t\tlog(ctx).Warn(\"error closing CPU profile output file:\", err)\n\t\t}\n\t}\n\n\tif err := pprof.StartCPUProfile(f); err != nil {\n\t\tcloser()\n\n\t\treturn errors.Wrap(err, \"could not start CPU profile\")\n\t}\n\n\tc.cpuProfileCloser = closer","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/cli/profile.go#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nkopia --profile-cpu --profile-directory /nonexistent-dir server start\n\n// after\nmkdir -p /var/tmp/kopia-profiles\nkopia --profile-cpu --profile-directory /var/tmp/kopia-profiles server start","handlingStrategy":"validation","validationCode":"profDir := flagProfileDirectory\nif info, err := os.Stat(profDir); err != nil || !info.IsDir() {\n\tos.MkdirAll(profDir, 0o755)\n}\nif f, err := os.CreateTemp(profDir, \".write-test\"); err != nil {\n\t// directory not writable: fix permissions/path before enabling profiling\n} else {\n\tf.Close(); os.Remove(f.Name())\n}","typeGuard":null,"tryCatchPattern":"if err := runKopia(args); err != nil {\n\tif strings.Contains(err.Error(), \"could not create CPU profile output file\") {\n\t\t// retry without profiling flags or with a writable profDir\n\t}\n}","preventionTips":["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."],"tags":["profiling","filesystem","permissions","pprof"],"backgroundTag":"file-write-failed","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}