{"record":{"id":"9964394569defe24","repo":"juicedata/juicefs","slug":"failed-to-write-footer-length-err-w-write-len","errorCode":null,"errorMessage":"failed to write footer length: err %w, write len %d, expect len 8","messagePattern":"failed to write footer length: err %w, write len (.+?), expect len 8","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/backup.go","lineNumber":193,"sourceCode":"\ntype BakFooter struct {\n\tMsg *pb.Footer\n\tLen uint64\n}\n\nfunc (h *BakFooter) Marshal(w io.Writer) error {\n\tdata, err := proto.Marshal(h.Msg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal footer: %w\", err)\n\t}\n\n\tif n, err := w.Write(data); err != nil && n != len(data) {\n\t\treturn fmt.Errorf(\"failed to write footer data: err %w, write len %d, expect len %d\", err, n, len(data))\n\t}\n\n\th.Len = uint64(len(data))\n\tif n, err := w.Write(binary.BigEndian.AppendUint64(nil, h.Len)); err != nil && n != 8 {\n\t\treturn fmt.Errorf(\"failed to write footer length: err %w, write len %d, expect len 8\", err, n)\n\t}\n\treturn nil\n}\n\nfunc (h *BakFooter) Unmarshal(r io.ReadSeeker) error {\n\tlenSize := int64(unsafe.Sizeof(h.Len))\n\t_, _ = r.Seek(-lenSize, io.SeekEnd)\n\n\tdata := make([]byte, lenSize)\n\tif n, err := r.Read(data); err != nil && n != int(lenSize) {\n\t\treturn fmt.Errorf(\"failed to read footer length: err %w, read len %d, expect len %d\", err, n, lenSize)\n\t}\n\n\th.Len = binary.BigEndian.Uint64(data)\n\t_, _ = r.Seek(-int64(h.Len)-lenSize, io.SeekEnd)\n\tdata = make([]byte, h.Len)\n\tif n, err := r.Read(data); err != nil && n != int(h.Len) {\n\t\treturn fmt.Errorf(\"failed to read footer: err %w, read len %d, expect len %d\", err, n, h.Len)","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/backup.go#L175-L211","documentation":"BakFooter.Marshal finishes by writing the 8-byte big-endian footer length. If the writer errors or writes fewer than 8 bytes, the footer (and thus the backup) is malformed and unreadable, so this wrapped error is returned.","triggerScenarios":"writeFooter → BakFooter.Marshal on the final length write when the destination stream fails: disk full, connection closed, or a short-write from a wrapped writer.","commonSituations":"Dumping to a full or quota-limited volume; streaming over an interrupted network connection; consumer of a pipe terminating before the dump completes.","solutions":["Free space on the destination and re-run the dump","Write the backup to a local file, then transfer it separately","Check network stability/timeouts for streamed dumps"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := f.writeFooter(w); err != nil {\n    if strings.Contains(err.Error(), \"failed to write footer length\") {\n        return fmt.Errorf(\"backup truncated at footer; retry dump: %w\", err)\n    }\n    return err\n}","preventionTips":["Guarantee free space/quota at destination","Use stable connections for streamed dumps","Never truncate a backup file manually"],"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-14T00:17:10.932Z"}