golangci/golangci-lint · error
can't write heap profile: %w
Error message
can't write heap profile: %w
What it means
golangci-lint wraps the error returned by pprof.WriteHeapProfile when dumping the heap profile to the --mem-profile-path file created moments earlier. Since the file was already created successfully, this is usually an I/O failure during the write itself (disk full, I/O error, closed fd).
Source
Thrown at pkg/commands/run.go:310
}
func (c *runCommand) stopTracing() error {
if c.opts.CPUProfilePath != "" {
pprof.StopCPUProfile()
}
if c.opts.MemProfilePath != "" {
f, err := os.Create(c.opts.MemProfilePath)
if err != nil {
return fmt.Errorf("can't create file %s: %w", c.opts.MemProfilePath, err)
}
var ms runtime.MemStats
runtime.ReadMemStats(&ms)
printMemStats(&ms, c.log)
if err := pprof.WriteHeapProfile(f); err != nil {
return fmt.Errorf("can't write heap profile: %w", err)
}
_ = f.Close()
}
if c.opts.TracePath != "" {
trace.Stop()
}
return nil
}
func (c *runCommand) runAndPrint(ctx context.Context) error {
if err := c.goenv.Discover(ctx); err != nil {
c.log.Warnf("Failed to discover go env: %s", err)
}
if !logutils.HaveDebugTag(logutils.DebugKeyLintersOutput) {
// Don't allow linters and loader to print anythingView on GitHub (pinned to ed7a235d2d)
Solutions
- Free disk space on the volume holding --mem-profile-path and re-run.
- Write the profile to a different, reliable local disk (e.g. /tmp) instead of a network mount.
- Check dmesg/storage health if I/O errors persist.
- Re-run the command; transient write failures often clear on retry.
Example fix
// before --mem-profile-path /mnt/nfs-share/mem.out # nfs write failed: no space left // after --mem-profile-path /tmp/mem.out
Defensive patterns
Strategy: try-catch
Validate before calling
if st, err := os.Stat(filepath.Dir(memPath)); err != nil || !st.IsDir() {
return fmt.Errorf("profile dir missing")
}
// roughly ensure free space
if usage := diskFreeBytes("/tmp"); usage < 64<<20 {
return fmt.Errorf("not enough free space for heap profile")
} Try / catch
if err := cmd.Run(); err != nil && strings.Contains(err.Error(), "can't write heap profile") {
log.Printf("heap profile write failed (disk full or I/O error); rerun after freeing space: %v", err)
} Prevention
- Monitor disk space on CI runners before profiling runs.
- Write profiles to local disk, not network mounts.
- Keep profile files small/lifecycle-managed (clean old artifacts).
When it happens
Trigger: Disk full or underlying storage error while pprof serializes the heap profile; file descriptor closed/invalidated between os.Create and WriteHeapProfile; rare pprof-internal serialization failures.
Common situations: CI machines with nearly full disks; ephemeral filesystems with tiny quotas; NFS/network volumes dropping connections mid-write.
Related errors
- can't start CPU profiling: %w
- can't create file %s: %w
- get base path: %w
- can't open file %s: %w
- can't create output for %s: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/6bac4767d3483639.
Report an issue: GitHub.