{"record":{"id":"a116739e11465069","repo":"juicedata/juicefs","slug":"failed-to-write-eos-err-w-write-len-d-expect","errorCode":null,"errorMessage":"failed to write EOS: err %w, write len %d, expect len 4","messagePattern":"failed to write EOS: err %w, write len (.+?), expect len 4","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/backup.go","lineNumber":159,"sourceCode":"\nfunc (f *BakFormat) ReadSegment(r io.Reader) (*BakSegment, error) {\n\tseg := &BakSegment{}\n\tif err := seg.Unmarshal(r); err != nil {\n\t\treturn nil, err\n\t}\n\treturn seg, nil\n}\n\nfunc (f *BakFormat) writeFooter(w io.Writer) error {\n\tif err := f.writeEOS(w); err != nil {\n\t\treturn err\n\t}\n\treturn f.Footer.Marshal(w)\n}\n\nfunc (f *BakFormat) writeEOS(w io.Writer) error {\n\tif n, err := w.Write(binary.BigEndian.AppendUint32(nil, BakEOS)); err != nil && n != 4 {\n\t\treturn fmt.Errorf(\"failed to write EOS: err %w, write len %d, expect len 4\", err, n)\n\t}\n\treturn nil\n}\n\nfunc (f *BakFormat) ReadFooter(r io.ReadSeeker) (*BakFooter, error) { // nolint:unused\n\tfooter := &BakFooter{}\n\tif err := footer.Unmarshal(r); err != nil {\n\t\treturn nil, err\n\t}\n\tif footer.Msg.Magic != BakMagic {\n\t\treturn nil, fmt.Errorf(\"invalid magic number %d, expect %d\", footer.Msg.Magic, BakMagic)\n\t}\n\tf.Footer = footer\n\treturn footer, nil\n}\n\ntype BakFooter struct {\n\tMsg *pb.Footer","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/backup.go#L141-L177","documentation":"writeEOS appends the 4-byte big-endian End-Of-Sections marker to the backup stream. The error fires when the io.Writer returns an error or a short write (n != 4), meaning the destination stream failed mid-write.","triggerScenarios":"Calling writeFooter → writeEOS when the underlying writer fails: disk full on the backup output file, closed connection to a network stream (HTTP body, pipe), or the writer returning io.ErrShortWrite.","commonSituations":"Dumping metadata to a full disk or quota-limited volume; writing a backup over an interrupted network stream (S3 multipart, HTTP upload); piping to a process that exited early (broken pipe).","solutions":["Check free space on the output destination and retry the dump","If streaming, verify the connection stayed open for the whole dump (timeouts, proxies)","Retry the dump writing to a local file first, then upload the completed file"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-flight: ensure destination has space\nst, err := os.Stat(destDir) // plus free-space check\nif free < expectedBackupSize { return errors.New(\"insufficient space for backup\") }","typeGuard":null,"tryCatchPattern":"if err := f.writeFooter(w); err != nil {\n    if strings.Contains(err.Error(), \"failed to write EOS\") || strings.Contains(err.Error(), \"short\") {\n        return fmt.Errorf(\"destination stream failed mid-dump, retry: %w\", err)\n    }\n    return err\n}","preventionTips":["Ensure ample free space at the dump destination","Avoid piping dumps over fragile streams; write to file first","Set generous network timeouts for streamed dumps"],"tags":["backup","io","write","short-write"],"backgroundTag":"file-write-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}