{"record":{"id":"4c0035f4618b2ea5","repo":"go-delve/delve","slug":"error-writing-to-output-file-v","errorCode":null,"errorMessage":"error writing to output file: %v","messagePattern":"error writing to output file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/dump.go","lineNumber":183,"sourceCode":"\t})\n\n\tthreads := t.ThreadList()\n\tstate.setThreadsTotal(len(threads))\n\n\tvar threadsDone bool\n\n\tif flags&DumpPlatformIndependent == 0 {\n\t\tthreadsDone, notes, err = t.proc.DumpProcessNotes(notes, state.threadDone)\n\t\tif err != nil {\n\t\t\tstate.setErr(err)\n\t\t\treturn\n\t\t}\n\t}\n\n\tif !threadsDone {\n\t\tfor _, th := range threads {\n\t\t\tif w.Err != nil {\n\t\t\t\tstate.setErr(fmt.Errorf(\"error writing to output file: %v\", w.Err))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif state.isCanceled() {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tnotes = t.dumpThreadNotes(notes, state, th)\n\t\t\tstate.threadDone()\n\t\t}\n\t}\n\n\tmemmap, err := t.proc.MemoryMap()\n\tif err != nil {\n\t\tstate.setErr(err)\n\t\treturn\n\t}\n\n\tmemmapFilter := make([]MemoryMapEntry, 0, len(memmap))\n\tmemtot := uint64(0)","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/dump.go#L165-L201","documentation":"Set in (*Target).Dump while iterating over threads to write thread notes: the elfwriter.Writer accumulated an error (w.Err) from a prior write, so Dump aborts before processing the remaining threads and records this wrapped error in DumpState.Err. It indicates the underlying output stream failed while the thread/register notes section was being produced.","triggerScenarios":"During (*Target).Dump, after notes have been written to the elfwriter.Writer (e.g. DumpProcessNotes or earlier thread notes), w.Err is non-nil when the per-thread loop starts — caused by a failed write to the output file (disk full, I/O error, closed file).","commonSituations":"Disk quota exceeded mid-dump on a large multi-threaded process; the output file descriptor became invalid; the user canceled/closed the destination file while the dump ran in a background goroutine.","solutions":["Free disk space or redirect the dump to a filesystem with sufficient capacity for the process's memory size.","Read the wrapped error to identify the concrete I/O failure (ENOSPC, EIO) and fix the root cause.","Ensure the output file stays open and writable for the entire dump; don't close it concurrently.","Retry the dump after resolving the I/O condition; check state.Err after DoneChan closes."],"exampleFix":"// before\nstate.Dumping = true\nf, _ := os.Create(path)\ngo target.Dump(f, flags, dstate)\n// (another goroutine) f.Close() early\n\n// after\nf, _ := os.Create(path)\ngo target.Dump(f, flags, dstate)\n<-dstate.DoneChan // wait until Dump has closed the file itself\nif dstate.Err != nil {\n    os.Remove(path)\n}","handlingStrategy":"try-catch","validationCode":"func canWriteDump(path string, need uint64) error {\n    var st syscall.Statfs_t\n    if err := syscall.Statfs(filepath.Dir(path), &st); err != nil {\n        return err\n    }\n    if uint64(st.Bavail)*uint64(st.Bsize) < need {\n        return fmt.Errorf(\"insufficient space for %d byte dump\", need)\n    }\n    return nil\n}","typeGuard":"func dumpFailed(state *proc.DumpState) bool {\n    state.Mutex.Lock()\n    defer state.Mutex.Unlock()\n    return state.Err != nil\n}","tryCatchPattern":"state := &proc.DumpState{DoneChan: make(chan struct{})}\ntarget.Dump(f, flags, state)\n<-state.DoneChan\nif state.Err != nil {\n    if strings.Contains(state.Err.Error(), \"error writing to output file\") {\n        // underlying stream failed; remove partial dump\n        os.Remove(outPath)\n    }\n    return state.Err\n}","preventionTips":["Verify destination free space before dumping a large process.","Keep the output file open and untouched for the whole dump; wait on DoneChan.","Avoid dumping to filesystems with tight quotas (tmpfs, home quotas).","Check state.Err immediately after every dump; never treat completion as success.","Retry only after fixing the concrete I/O error wrapped in the message."],"tags":["go","core-dump","file-io","elf"],"backgroundTag":"core-dump-write-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}