juicedata/juicefs · error
failed to write EOS: err %w, write len %d, expect len 4
Error message
failed to write EOS: err %w, write len %d, expect len 4
What it means
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.
Source
Thrown at pkg/meta/backup.go:159
func (f *BakFormat) ReadSegment(r io.Reader) (*BakSegment, error) {
seg := &BakSegment{}
if err := seg.Unmarshal(r); err != nil {
return nil, err
}
return seg, nil
}
func (f *BakFormat) writeFooter(w io.Writer) error {
if err := f.writeEOS(w); err != nil {
return err
}
return f.Footer.Marshal(w)
}
func (f *BakFormat) writeEOS(w io.Writer) error {
if n, err := w.Write(binary.BigEndian.AppendUint32(nil, BakEOS)); err != nil && n != 4 {
return fmt.Errorf("failed to write EOS: err %w, write len %d, expect len 4", err, n)
}
return nil
}
func (f *BakFormat) ReadFooter(r io.ReadSeeker) (*BakFooter, error) { // nolint:unused
footer := &BakFooter{}
if err := footer.Unmarshal(r); err != nil {
return nil, err
}
if footer.Msg.Magic != BakMagic {
return nil, fmt.Errorf("invalid magic number %d, expect %d", footer.Msg.Magic, BakMagic)
}
f.Footer = footer
return footer, nil
}
type BakFooter struct {
Msg *pb.FooterView on GitHub (pinned to c9a67b23e8)
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
Defensive patterns
Strategy: retry
Validate before calling
// pre-flight: ensure destination has space
st, err := os.Stat(destDir) // plus free-space check
if free < expectedBackupSize { return errors.New("insufficient space for backup") } Try / catch
if err := f.writeFooter(w); err != nil {
if strings.Contains(err.Error(), "failed to write EOS") || strings.Contains(err.Error(), "short") {
return fmt.Errorf("destination stream failed mid-dump, retry: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- failed to write footer data: err %w, write len %d, expect le
- failed to write footer length: err %w, write len %d, expect
- failed to write segment data %s: err %w, write len %d, expec
- failed to read footer length: err %w, read len %d, expect le
- failed to read footer: err %w, read len %d, expect len %d
AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06).
Data as JSON: /api/errors/a116739e11465069.
Report an issue: GitHub.