{"record":{"id":"e52ad9bf2fa3f24c","repo":"microsoft/typescript-go","slug":"failed-to-create-heap-profile-file-w","errorCode":null,"errorMessage":"failed to create heap profile file: %w","messagePattern":"failed to create heap profile file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pprof/pprof.go","lineNumber":132,"sourceCode":"\t}\n\n\tfilePath := c.session.cpuFilePath\n\tc.session.Stop()\n\tc.session = nil\n\n\treturn filePath, nil\n}\n\n// SaveHeapProfile saves a heap profile to the specified directory.\nfunc SaveHeapProfile(profileDir string) (string, error) {\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\theapProfilePath := filepath.Join(profileDir, fmt.Sprintf(\"%d-%d-heapprofile.pb.gz\", os.Getpid(), time.Now().UnixMilli()))\n\theapFile, err := os.Create(heapProfilePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create heap profile file: %w\", err)\n\t}\n\tdefer heapFile.Close()\n\n\truntime.GC()\n\tif err := pprof.Lookup(\"heap\").WriteTo(heapFile, 0); err != nil {\n\t\tos.Remove(heapProfilePath)\n\t\treturn \"\", fmt.Errorf(\"failed to write heap profile: %w\", err)\n\t}\n\n\treturn heapProfilePath, nil\n}\n\n// SaveAllocProfile saves an allocation profile to the specified directory.\nfunc SaveAllocProfile(profileDir string) (string, error) {\n\tif err := os.MkdirAll(profileDir, 0o755); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create profile directory: %w\", err)\n\t}\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/pprof/pprof.go#L114-L150","documentation":"SaveHeapProfile could not os.Create the generated heap profile file (<pid>-<millis>-heapprofile.pb.gz) inside an existing directory. Pure file-level failure after successful mkdir: permission mismatch, ENOSPC, filesystem I/O error, or policy denial. The heap snapshot is not taken.","triggerScenarios":"Sticky-bit directory owned by another user; disk full at the moment of the dump; network filesystem rejecting the create; security policy blocking gz writes in that path.","commonSituations":"Memory-incident automation firing when the disk is already full (correlated events); shared /tmp with restrictive modes; container security profiles.","solutions":["Free space or redirect profileDir to a volume with headroom","Run a write probe into the directory before triggering the dump","Fix directory ownership/permissions for the server user"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if writable, err := canCreateFile(profileDir); !writable {\n\treturn fmt.Errorf(\"heap dump target not writable: %w\", err)\n}\n\nfunc canCreateFile(dir string) (bool, error) {\n\tf, err := os.CreateTemp(dir, \"probe-*\")\n\tif err != nil { return false, err }\n\tf.Close()\n\treturn true, os.Remove(f.Name())\n}","typeGuard":null,"tryCatchPattern":"if _, err := pprof.SaveHeapProfile(dir); err != nil {\n\tvar perr *fs.PathError\n\tif errors.As(err, &perr) && (perr.Err == syscall.EACCES || perr.Err == syscall.ENOSPC) {\n\t\treturn pprof.SaveHeapProfile(os.TempDir())\n\t}\n\treturn \"\", err\n}","preventionTips":["Probe file creation in the dump directory before incidents occur","Reserve disk headroom for diagnostics","Fix directory modes (sticky-bit directories need ownership or the sticky mode)"],"tags":["pprof","heap","disk-full","permissions"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}