nats-io/nats-server · warning

filestore is nil

Error message

filestore is nil

What it means

Guard in (*fileStore).ConsumerStore: creating a consumer store on a nil fileStore pointer returns this error immediately. It is a defensive programming check — normal users should never be able to call the method on a nil file store, so hitting it indicates an internal state bug in the server.

Source

Thrown at server/filestore.go:13329

	cfg     *FileConsumerInfo
	prf     keyGen
	aek     cipher.AEAD
	name    string
	odir    string
	ifn     string
	hh      *highwayhash.Digest64
	state   ConsumerState
	fch     chan struct{}
	qch     chan struct{}
	flusher bool
	writing bool
	dirty   bool
	closed  bool
}

func (fs *fileStore) ConsumerStore(name string, created time.Time, cfg *ConsumerConfig) (ConsumerStore, error) {
	if fs == nil {
		return nil, fmt.Errorf("filestore is nil")
	}
	if fs.isClosed() {
		return nil, ErrStoreClosed
	}
	if cfg == nil || name == _EMPTY_ {
		return nil, fmt.Errorf("bad consumer config")
	}

	// We now allow overrides from a stream being a filestore type and forcing a consumer to be memory store.
	if cfg.MemoryStorage {
		// Create directly here.
		o := &consumerMemStore{ms: fs, name: name, cfg: *cfg}
		if err := fs.AddConsumer(o); err != nil {
			return nil, err
		}
		return o, nil
	}

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Audit the code path that produced a nil *fileStore — stream creation should have failed earlier.
  2. In embedded usage, ensure the file store was successfully created and not set to nil before creating consumers.
  3. Check earlier logs for stream creation errors that were ignored.
  4. Report to nats-server maintainers with a reproduction if it happens in stock operation.
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure the stream store is initialized before creating consumers
if fsStore == nil {
    return errors.New("file store not initialized; create the stream first")
}

Type guard

func fsReady(fs *server.FileStore) bool { return fs != nil }

Try / catch

if err != nil {
    if err.Error() == "filestore is nil" {
        log.Printf("internal init bug: stream store nil at consumer creation")
    }
}

Prevention

When it happens

Trigger: ConsumerStore(name, created, cfg) invoked on a *fileStore that is nil, which only occurs due to internal logic errors or test harness misuse of the filestore API.

Common situations: Custom builds, embedded nats-server usage with misuse of internal APIs, or test code constructing streams that fail to initialize but are still used.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/fb57d8e36fe90e9f. Report an issue: GitHub.