nats-io/nats-server · error

couldn't load next message after seq %d: %s

Error message

couldn't load next message after seq %d: %s

What it means

Emitted while the snapshot iterates stream messages via store.LoadNextMsg. After filtering out the normal ErrStoreEOF end-of-stream sentinel, any remaining error from the message store (I/O failure, index corruption, purged/missing sequence) is reported with the sequence where iteration stopped, terminating the backup.

Source

Thrown at server/stream_backup.go:229

				}
				if err := writeConsumerMsg(SnapshotConsumerState{
					ConsumerConfig: config,
					ConsumerState:  state,
				}); err != nil {
					errCh <- err
					return
				}
			}
		}
	}

	var sm StoreMsg
	for seq := state.FirstSeq - 1; seq < state.LastSeq; {
		if _, seq, err = store.LoadNextMsg(fwcs, true, seq+1, &sm); err != nil {
			if err == ErrStoreEOF {
				break
			}
			errCh <- fmt.Errorf("couldn't load next message after seq %d: %s", seq+1, err)
			return
		}
		if err = writeStoreMsg(&sm); err != nil {
			errCh <- err
			return
		}
	}

	// End of backup sentinel. A clear marker makes it obvious when
	// a backup has been truncated or not without having to count
	// messages or from first/last sequence, which may not be possible
	// during the rewrite of a large stream backup.
	if err = writeGeneric(_EMPTY_, 0, 0, 0, 0, nil); err != nil {
		errCh <- err
	}
}

// RestoreStreamSnapshotV2 will restore a stream from a snapshot.

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Check server logs for file-store errors (disk failures, corrupted indexes) around the reported sequence
  2. Run store consistency checks or rebuild the stream from replicas/backup
  3. Free disk space and re-attempt the backup once the underlying store error is resolved
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at server/stream_backup.go:229 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/780798d48de76c66. Report an issue: GitHub.