{"record":{"id":"6bac4767d3483639","repo":"golangci/golangci-lint","slug":"can-t-write-heap-profile-w","errorCode":null,"errorMessage":"can't write heap profile: %w","messagePattern":"can't write heap profile: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/run.go","lineNumber":310,"sourceCode":"}\n\nfunc (c *runCommand) stopTracing() error {\n\tif c.opts.CPUProfilePath != \"\" {\n\t\tpprof.StopCPUProfile()\n\t}\n\n\tif c.opts.MemProfilePath != \"\" {\n\t\tf, err := os.Create(c.opts.MemProfilePath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't create file %s: %w\", c.opts.MemProfilePath, err)\n\t\t}\n\n\t\tvar ms runtime.MemStats\n\t\truntime.ReadMemStats(&ms)\n\t\tprintMemStats(&ms, c.log)\n\n\t\tif err := pprof.WriteHeapProfile(f); err != nil {\n\t\t\treturn fmt.Errorf(\"can't write heap profile: %w\", err)\n\t\t}\n\t\t_ = f.Close()\n\t}\n\n\tif c.opts.TracePath != \"\" {\n\t\ttrace.Stop()\n\t}\n\n\treturn nil\n}\n\nfunc (c *runCommand) runAndPrint(ctx context.Context) error {\n\tif err := c.goenv.Discover(ctx); err != nil {\n\t\tc.log.Warnf(\"Failed to discover go env: %s\", err)\n\t}\n\n\tif !logutils.HaveDebugTag(logutils.DebugKeyLintersOutput) {\n\t\t// Don't allow linters and loader to print anything","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L292-L328","documentation":"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).","triggerScenarios":"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.","commonSituations":"CI machines with nearly full disks; ephemeral filesystems with tiny quotas; NFS/network volumes dropping connections mid-write.","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."],"exampleFix":"// before\n--mem-profile-path /mnt/nfs-share/mem.out   # nfs write failed: no space left\n// after\n--mem-profile-path /tmp/mem.out","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(filepath.Dir(memPath)); err != nil || !st.IsDir() {\n\treturn fmt.Errorf(\"profile dir missing\")\n}\n// roughly ensure free space\nif usage := diskFreeBytes(\"/tmp\"); usage < 64<<20 {\n\treturn fmt.Errorf(\"not enough free space for heap profile\")\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil && strings.Contains(err.Error(), \"can't write heap profile\") {\n\tlog.Printf(\"heap profile write failed (disk full or I/O error); rerun after freeing space: %v\", err)\n}","preventionTips":["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)."],"tags":["profiling","pprof","io","filesystem","golangci-lint"],"backgroundTag":"disk-full-write-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}