nats-io/nats-server · error
Stream state detected prior state, could not locate msg…
Error message
Stream state detected prior state, could not locate msg block %d
What it means
During stream recovery, a message block marked closed (its file was missing on disk even though the block index expected it, e.g. after a crash or manual deletion) could not be located. The store rebuilds state from remaining blocks, records any lost data, and returns errPriorState so callers know prior state was superseded.
Solutions
- Check for manually deleted or moved message block files under the msg dir
- Let the rebuild complete; lost data is tracked via addLostData
- Restore block files from backup if data loss is unacceptable
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at server/filestore.go:2222 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/984b79c12ce44559.
Report an issue: GitHub.
Appendix: source
Thrown at server/filestore.go:2222
}
if n, err := fmt.Sscanf(fi.Name(), blkScan, &index); err == nil && n == 1 {
if index > blkIndex {
fs.warn("Stream state outdated, found extra blocks, will rebuild")
return errPriorState
} else if mb, ok := fs.bim[index]; ok {
mb.closed = false
}
}
}
var rebuild bool
for _, mb := range fs.blks {
if mb.closed {
rebuild = true
if ld, _, _ := mb.rebuildState(); ld != nil {
fs.addLostData(ld)
}
fs.warn("Stream state detected prior state, could not locate msg block %d", mb.index)
}
}
if rebuild {
return errPriorState
}
// We check first and last seq and number of msgs and bytes. If there is a difference,
// return and error so we rebuild from the message block state on disk.
if !trackingStatesEqual(&fs.state, &mstate) {
_ = os.Remove(fn)
fs.warn("Stream state encountered internal inconsistency on recover")
return errCorruptState
}
return nil
}
// Recover per-message state like TTLs and schedules. Doing a linear scan through the streamView on GitHub (pinned to 3a66a489d2)