nats-io/nats-server · error
memstore is nil
Error message
memstore is nil
What it means
Nil-receiver guard in memStore.ConsumerStore: the method was invoked on a nil *memStore, meaning the stream store was never created or has been torn down before a consumer was attached to it.
Source
Thrown at server/memstore.go:2594
func (ms *memStore) isClosed() bool {
ms.mu.RLock()
defer ms.mu.RUnlock()
return ms.msgs == nil
}
type consumerMemStore struct {
mu sync.Mutex
ms StreamStore
name string
cfg ConsumerConfig
state ConsumerState
closed bool
}
func (ms *memStore) ConsumerStore(name string, _ time.Time, cfg *ConsumerConfig) (ConsumerStore, error) {
if ms == nil {
return nil, fmt.Errorf("memstore is nil")
}
if ms.isClosed() {
return nil, ErrStoreClosed
}
if cfg == nil || name == _EMPTY_ {
return nil, fmt.Errorf("bad consumer config")
}
o := &consumerMemStore{ms: ms, name: name, cfg: *cfg}
ms.AddConsumer(o)
return o, nil
}
func (ms *memStore) AddConsumer(o ConsumerStore) error {
ms.mu.Lock()
ms.consumers = append(ms.consumers, o)
ms.mu.Unlock()
return nil
}View on GitHub (pinned to 3a66a489d2)
Solutions
- Check that the stream store was successfully created before adding consumers
- Tear down consumers before closing/deleting the stream store
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at server/memstore.go:2594 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/d804bbfe9b2790fd.
Report an issue: GitHub.