benbjohnson/litestream · error
decode header: %w
Error message
decode header: %w
What it means
ltx.Decoder.DecodeHeader failed on the opened LTX stream in applyLTXFile. The downloaded file is not a valid LTX — truncated body, bad magic, or unsupported version — so its pages cannot be safely applied.
Source
Thrown at replica.go:955
// applyLTXFile applies a single LTX file's pages to the database file.
// This follows the same pattern as Hydrator.ApplyLTX (vfs.go:712-747).
//
// To prevent concurrent SQLite readers from seeing partial updates, we acquire
// an exclusive file lock before writing. We also rewrite the SQLite header
// (bytes 18-19) to indicate DELETE journal mode instead of WAL mode, and
// randomize the schema change counter (bytes 24-27) to invalidate cached
// schemas in other connections.
func (r *Replica) applyLTXFile(ctx context.Context, f *os.File, info *ltx.FileInfo, pageSize uint32) error {
rc, err := r.Client.OpenLTXFile(ctx, info.Level, info.MinTXID, info.MaxTXID, 0, 0)
if err != nil {
return fmt.Errorf("open ltx file: %w", err)
}
defer rc.Close()
dec := ltx.NewDecoder(rc)
if err := dec.DecodeHeader(); err != nil {
return fmt.Errorf("decode header: %w", err)
}
hdr := dec.Header()
if err := internal.LockFileExclusive(f); err != nil {
return fmt.Errorf("acquire exclusive lock: %w", err)
}
defer internal.UnlockFile(f)
for {
var phdr ltx.PageHeader
data := make([]byte, pageSize)
if err := dec.DecodePage(&phdr, data); err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("decode page: %w", err)
}
View on GitHub (pinned to 4ed7a308f6)
Solutions
- Delete and re-upload the corrupted LTX object
- Inspect it with 'litestream ltx -level N' to confirm corruption
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at replica.go:955 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/5a0cfe6623608e54.
Report an issue: GitHub.