clockworklabs/SpacetimeDB · error · io::Error
unexpected EOF while validating commit at byte offset
Error message
unexpected EOF while validating commit at byte offset {byte_offset} What it means
validate_commit_at_byte_offset seeks to the byte offset recorded in the offset index and decodes a StoredCommit. Decode returned None (no bytes available), so the index points beyond the end of the actual commit data, typically into a truncated or preallocated tail, yielding ErrorKind::UnexpectedEof with the byte offset in the message.
Solutions
- Rebuild the offset index from segment data (delete index files and reopen)
- Treat trailing invalid data as recoverable: trim to the last valid commit and rebuild
- Fall back to scanning the segment sequentially instead of trusting the index
- Verify fsync ordering (data before index) in your build/deployment if this recurs
Defensive patterns
Strategy: fallback
Type guard
fn is_index_eof(err: &io::Error) -> bool {
err.kind() == io::ErrorKind::UnexpectedEof
&& err.to_string().contains("validating commit at byte offset")
} Try / catch
match seek_with_index(&mut segment, &mut index, key) {
Ok(pos) => Some(pos),
Err(e) if is_index_eof(&e) => {
// index points past valid data: scan sequentially instead
scan_segment_for_tx(&mut segment, key).await.ok()
}
Err(e) => return Err(e),
} Prevention
- Bound index entries to flushed commit data only (data fsync before index fsync)
- Trim trailing invalid data on recovery so indexes never point into the tail
- Rebuild indexes after any crash recovery event
When it happens
Trigger: Index entry written before its commit data was flushed, then a crash left the data absent; segment truncated externally after the index was built; seeking to an entry that points past the last valid commit.
Common situations: Kill -9 mid-commit with the async index fsync ordering; disk-level truncation; replaying a directory restored from a snapshot taken mid-write.
Related errors
- failed to decode commit
- failed to read segment header
- Failed to truncate offset index
- mismatch key in index offset file: expected=
- mismatched key in offset index file
AI-assisted analysis of clockworklabs/SpacetimeDB@3653d2ed49 (2026-08-20).
Data as JSON: /api/errors/3dfa7045b9403527.
Report an issue: GitHub.
Appendix: source
Thrown at crates/commitlog/src/segment.rs:540
/// Try to extract the commit header from the asked position without advancing seek.
/// `IndexFileMut` fsync asynchoronously, which makes it important for reader to verify its entry
fn validate_commit_at_byte_offset<Reader: io::Read + io::Seek>(
mut reader: &mut Reader,
byte_offset: u64,
) -> io::Result<commit::Header> {
let pos = reader.stream_position()?;
reader.seek(SeekFrom::Start(byte_offset))?;
let hdr_or_error = StoredCommit::decode(&mut reader).and_then(|maybe_commit| {
let StoredCommit {
min_tx_offset,
epoch,
n,
records,
..
} = maybe_commit.ok_or_else(|| {
io::Error::new(
ErrorKind::UnexpectedEof,
format!("unexpected EOF while validating commit at byte offset {byte_offset}"),
)
})?;
Ok(commit::Header {
min_tx_offset,
epoch,
n,
len: records.len() as u32,
})
});
// Restore the original position
reader.seek(SeekFrom::Start(pos))?;
hdr_or_error
}View on GitHub (pinned to 3653d2ed49)