{"record":{"id":"67a6e33017616b06","repo":"microsoft/typescript-go","slug":"failed-to-create-cpu-profile-file-w","errorCode":null,"errorMessage":"failed to create CPU profile file: %w","messagePattern":"failed to create CPU profile file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pprof/pprof.go","lineNumber":90,"sourceCode":"}\n\n// StartCPUProfile starts CPU profiling, writing to the specified directory when stopped.\nfunc (c *CPUProfiler) StartCPUProfile(profileDir string) error {\n\tc.mu.Lock()\n\tdefer c.mu.Unlock()\n\n\tif c.session != nil {\n\t\treturn errors.New(\"CPU profiling already in progress\")\n\t}\n\n\tif err := os.MkdirAll(profileDir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create profile directory: %w\", err)\n\t}\n\n\tcpuProfilePath := filepath.Join(profileDir, fmt.Sprintf(\"%d-%d-cpuprofile.pb.gz\", os.Getpid(), time.Now().UnixMilli()))\n\tcpuFile, err := os.Create(cpuProfilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create CPU profile file: %w\", err)\n\t}\n\n\tif err := pprof.StartCPUProfile(cpuFile); err != nil {\n\t\tcpuFile.Close()\n\t\tos.Remove(cpuProfilePath)\n\t\treturn fmt.Errorf(\"failed to start CPU profile: %w\", err)\n\t}\n\n\tc.session = &ProfileSession{\n\t\tcpuFilePath: cpuProfilePath,\n\t\tcpuFile:     cpuFile,\n\t\tlogWriter:   io.Discard,\n\t}\n\treturn nil\n}\n\n// StopCPUProfile stops CPU profiling and returns the path to the profile file.\nfunc (c *CPUProfiler) StopCPUProfile() (string, error) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/pprof/pprof.go#L72-L108","documentation":"StartCPUProfile could not os.Create the CPU profile file inside the (already created) profile directory. The file name is generated as <pid>-<millis>-cpuprofile.pb.gz. Directory creation succeeded, so failure is at file level: permission on the directory, disk full, name collisions, or filesystem-level I/O errors.","triggerScenarios":"Directory is writable for mkdir but the process lacks file-creation rights (sticky bit / different owner); ENOSPC; NFS/network volume refusing the create; SELinux/AppArmor denying writes in the profile location.","commonSituations":"Hardened servers where /tmp is noexec/nodev/nosticky-managed; disk exhaustion during long capture sessions; container volume quotas hit.","solutions":["Verify with a manual touch of a file in the same directory as the server user","Free disk space or move profileDir to a volume with capacity","Adjust SELinux/AppArmor policy or pick a permitted path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify file creation is possible in the target directory\nprobe, err := os.CreateTemp(profileDir, \"probe-*\")\nif err != nil {\n\treturn fmt.Errorf(\"profile dir not writable: %w\", err)\n}\nprobe.Close()\nos.Remove(probe.Name())","typeGuard":null,"tryCatchPattern":"if err := profiler.StartCPUProfile(dir); err != nil {\n\tif isFileCreationErr(err) { // EACCES / ENOSPC / EDQUOT\n\t\treturn fmt.Errorf(\"cannot write profile file in %s: %w\", dir, err)\n\t}\n\treturn err\n}","preventionTips":["Check disk space and directory permissions before starting profiles","Run the server as a user with write access to the profile directory","Monitor disk usage when long capture sessions are expected"],"tags":["pprof","filesystem","permissions","disk-full"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}