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

  1. Guarantee free space proportional to allocation volume before dumping
  2. Dump to local disk, then ship the artifact
  3. 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

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


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/ade9db7df2cc59fc. Report an issue: GitHub.