nats-io/nats-server · warning
short index file
Error message
short index file
What it means
Returned when a file-store index file is shorter than the parsed position plus checksum size — i.e. the index file is truncated or was written incompletely (a short write during index creation). The store deletes the index file and returns this error, after which the index is rebuilt from the message block data.
Source
Thrown at server/filestore.go:10172
if n <= 0 {
bi = -1
return -1
}
bi += n
return ts
}
mb.msgs = readCount()
mb.bytes = readCount()
atomic.StoreUint64(&mb.first.seq, readSeq())
mb.first.ts = readTimeStamp()
atomic.StoreUint64(&mb.last.seq, readSeq())
mb.last.ts = readTimeStamp()
dmapLen := readCount()
// Check if this is a short write index file.
if bi < 0 || bi+checksumSize > len(buf) {
os.Remove(ifn)
return fmt.Errorf("short index file")
}
// Check for consistency if accounting. If something is off bail and we will rebuild.
if mb.msgs != (atomic.LoadUint64(&mb.last.seq)-atomic.LoadUint64(&mb.first.seq)+1)-dmapLen {
os.Remove(ifn)
return fmt.Errorf("accounting inconsistent")
}
// Checksum
copy(mb.lchk[0:], buf[bi:bi+checksumSize])
bi += checksumSize
// Now check for presence of a delete map
if dmapLen > 0 {
// New version is encoded avl seqset.
if buf[1] == newVersion {
dmap, _, err := avl.Decode(buf[bi:])
if err != nil {View on GitHub (pinned to 3a66a489d2)
Solutions
- Retry/restart — the truncated index file is removed automatically and rebuilt from block data.
- Check for past disk-full events or unclean shutdowns in server logs.
- If index rebuilds fail repeatedly, verify filesystem integrity (fsck) and disk health.
- Ensure clean shutdowns (SIGTERM/SIGINT, not SIGKILL) to avoid partial index writes.
Defensive patterns
Strategy: fallback
Try / catch
if err != nil && strings.Contains(err.Error(), "short index file") {
// truncated index removed and rebuilt; verify subsequent reads succeed
} Prevention
- Ensure sufficient disk space so index writes never truncate.
- Shut down cleanly; avoid kill -9 and power loss (use UPS).
- Run filesystem checks if truncation recurs.
- Alert on index-rebuild log lines as an early corruption signal.
When it happens
Trigger: Loading an index where the read position bi is invalid or bi+checksumSize exceeds len(buf), meaning the index buffer ended prematurely (e.g. crash mid-index-write leaving a partial file).
Common situations: Power loss or kill -9 during index file creation, disk-full during index write, or corrupted/truncated files after storage failures.
Related errors
- bad index file
- accounting inconsistent
- fileStore requires file storage type in config
- filestore max block size is %s
- could not create hash: %v
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/d0f62dff4381ff82.
Report an issue: GitHub.