microsoft/typescript-go · error
failed to write alloc profile: %w
Error message
failed to write alloc profile: %w
What it means
SaveAllocProfile failed while pprof.Lookup("allocs").WriteTo serialized the allocation profile to the opened file. The partial file is removed and the error wrapped. This is a mid-write I/O failure (disk full while writing a large alloc profile, EIO on failing storage) since the file was successfully created moments earlier.
Source
Thrown at internal/pprof/pprof.go:160
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
- Guarantee free space proportional to allocation volume before dumping
- Dump to local disk, then ship the artifact
- Retry after resolving the storage condition
Defensive patterns
Strategy: retry
Validate before calling
if free := diskFree(profileDir); free < minFreeForAllocProfile {
return fmt.Errorf("need at least %d free for alloc profile", minFreeForAllocProfile)
} Try / catch
path, err := pprof.SaveAllocProfile(dir)
if err != nil && strings.Contains(err.Error(), "failed to write alloc profile") {
path, err = pprof.SaveAllocProfile(os.TempDir()) // local retry, fresh target
}
if err != nil { return "", err } Prevention
- Write alloc profiles to local disk with ample free space
- Retry once on transient storage errors, then surface the failure
- Size reserved diagnostics space to the allocation volume of the process
When it happens
Trigger: ENOSPC during serialization of a large allocation profile on a memory-heavy process; EIO on failing disks or flaky network mounts; writer interrupted by storage-layer errors.
Common situations: Profiling triggered during incidents when the disk is already near capacity; allocs profiles on long-running servers being gigabyte-scale; FUSE mounts with hard size limits.
Related errors
- failed to write heap profile: %w
- failed to create alloc profile file: %w
- Cannot parse string enum value: ${goValue}
- failed to create CPU profile file: %w
- failed to create heap profile file: %w
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/ade9db7df2cc59fc.
Report an issue: GitHub.