{"record":{"id":"64edc9ef6e035c3c","repo":"pulumi/pulumi","slug":"could-not-start-cpu-profile-w","errorCode":null,"errorMessage":"could not start CPU profile: %w","messagePattern":"could not start CPU profile: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/common/util/cmdutil/profile.go","lineNumber":31,"sourceCode":"// limitations under the License.\n\npackage cmdutil\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"runtime\"\n\t\"runtime/pprof\"\n\t\"runtime/trace\"\n\t\"time\"\n\n\t\"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract\"\n)\n\nfunc InitProfiling(prefix string, memProfileRate int) error {\n\tcpu, err := os.Create(fmt.Sprintf(\"%s.%v.cpu\", prefix, os.Getpid()))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not start CPU profile: %w\", err)\n\t}\n\tif err = pprof.StartCPUProfile(cpu); err != nil {\n\t\treturn fmt.Errorf(\"could not start CPU profile: %w\", err)\n\t}\n\n\texec, err := os.Create(fmt.Sprintf(\"%s.%v.trace\", prefix, os.Getpid()))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not start execution trace: %w\", err)\n\t}\n\tif err = trace.Start(exec); err != nil {\n\t\treturn fmt.Errorf(\"could not start execution trace: %w\", err)\n\t}\n\n\tif memProfileRate > 0 {\n\t\truntime.MemProfileRate = memProfileRate\n\t\tgo memoryProfileWriteLoop(prefix)\n\t}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/common/util/cmdutil/profile.go#L13-L49","documentation":"InitProfiling wraps failures from either creating the CPU profile output file or starting pprof.StartCPUProfile. Both the file-create error and the pprof start error share this message, prefixed with the given prefix and PID.","triggerScenarios":"Running the CLI with profiling enabled (e.g. PULUMI_SKIP_AUTOMATION... / profiling flags or env enabling InitProfiling) where the <prefix>.<pid>.cpu file cannot be created (bad path, read-only dir, permissions) or a CPU profile is already running in-process.","commonSituations":"Profiling output directory doesn't exist or is not writable; running as a user without write permission to prefix location; nested/second call to StartCPUProfile within the same process; disk full.","solutions":["Ensure the profiling output prefix points to an existing writable directory (e.g. /tmp)","Check disk space and file permissions for the profile file location","Disable profiling (unset the profiling env/flag) if you don't need it","Verify only one InitProfiling call per process lifetime"],"exampleFix":"// before\nPULUMI_PROFILE_PREFIX=/nonexistent/dir/pulumi\n// after\nPULUMI_PROFILE_PREFIX=/tmp/pulumi","handlingStrategy":"try-catch","validationCode":"// ensure profile output location is writable before enabling profiling\nif err := os.MkdirAll(profDir, 0o755); err != nil { return err }\nif f, err := os.CreateTemp(profDir, \"prof-check\"); err != nil { return err } else { f.Close(); os.Remove(f.Name()) }","typeGuard":null,"tryCatchPattern":"if err := cmdutil.InitProfiling(prefix, memProfileRate); err != nil {\n    // profiling is best-effort: log and continue without profiling\n    log.Printf(\"profiling disabled: %v\", err)\n}","preventionTips":["Point profiling output at a writable directory like /tmp","Check free disk space before enabling profiling","Enable profiling only once per process","Disable profiling when not debugging"],"tags":["go","cli","profiling","pprof"],"backgroundTag":"profiler-start-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}