microsoft/typescript-go · error
failed to create alloc profile file: %w
Error message
failed to create alloc profile file: %w
What it means
SaveAllocProfile could not os.Create the alloc profile file in an existing directory. Mirrors the heap-file error: mkdir succeeded but creating the output file failed — permission mode on the directory, ENOSPC, filesystem policy, or I/O error. No profile is written.
Source
Thrown at internal/pprof/pprof.go:154
runtime.GC()
if err := pprof.Lookup("heap").WriteTo(heapFile, 0); err != nil {
os.Remove(heapProfilePath)
return "", fmt.Errorf("failed to write heap profile: %w", err)
}
return heapProfilePath, nil
}
// SaveAllocProfile saves an allocation profile to the specified directory.
func SaveAllocProfile(profileDir string) (string, error) {
if err := os.MkdirAll(profileDir, 0o755); err != nil {
return "", fmt.Errorf("failed to create profile directory: %w", err)
}
allocProfilePath := filepath.Join(profileDir, fmt.Sprintf("%d-%d-allocprofile.pb.gz", os.Getpid(), time.Now().UnixMilli()))
allocFile, err := os.Create(allocProfilePath)
if err != nil {
return "", fmt.Errorf("failed to create alloc profile file: %w", err)
}
defer allocFile.Close()
if err := pprof.Lookup("allocs").WriteTo(allocFile, 0); err != nil {
os.Remove(allocProfilePath)
return "", fmt.Errorf("failed to write alloc profile: %w", err)
}
return allocProfilePath, nil
}
// RunGC triggers garbage collection.
func RunGC() {
runtime.GC()
}
View on GitHub (pinned to 1bcfa18d79)
Solutions
- Probe writability (create a temp file) in the target directory before the real call
- Fix ownership/permissions or relocate profileDir
- Free disk space
Defensive patterns
Strategy: try-catch
Validate before calling
if f, err := os.CreateTemp(profileDir, "probe-*"); err != nil {
return fmt.Errorf("alloc dump target unusable: %w", err)
} else {
f.Close()
os.Remove(f.Name())
} Try / catch
if _, err := pprof.SaveAllocProfile(dir); err != nil {
var perr *fs.PathError
if errors.As(err, &perr) && (perr.Err == syscall.EACCES || perr.Err == syscall.ENOSPC) {
return pprof.SaveAllocProfile(os.TempDir())
}
return "", err
} Prevention
- Probe writability before the incident, not during
- Keep quota headroom for alloc profiles on long-lived servers
- Fix directory ownership for the server user
When it happens
Trigger: Directory writable for mkdir (already existed) but file creation denied; disk full; SELinux/AppArmor denial; NFS create refusal.
Common situations: Existing directories with restrictive modes (root-created dump dirs); quota-exceeded volumes; security-hardened hosts.
Related errors
- failed to create CPU profile file: %w
- failed to create heap profile file: %w
- failed to write alloc profile: %w
- failed to create profile directory: %w
- failed to write heap profile: %w
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/28ecbf11cb46b378.
Report an issue: GitHub.