nats-io/nats-server · error

no internal account client

Error message

no internal account client

What it means

The account's internal client used to process internal subscriptions is nil (server/accounts.go:2251). This happens when an internal subscription is requested before the account has been fully set up/registered with the server.

Source

Thrown at server/accounts.go:2251

	if ic := a.internalClient(); ic != nil {
		ic.processUnsub(sub.sid)
	}
}

// Creates internal subscription for service import responses.
func (a *Account) subscribeServiceImportResponse(subject string) (*subscription, error) {
	return a.subscribeInternalEx(subject, a.processServiceImportResponse, true)
}

func (a *Account) subscribeInternalEx(subject string, cb msgHandler, ri bool) (*subscription, error) {
	a.mu.Lock()
	a.isid++
	c, sid := a.internalClient(), strconv.FormatUint(a.isid, 10)
	a.mu.Unlock()

	// This will happen in parsing when the account has not been properly setup.
	if c == nil {
		return nil, fmt.Errorf("no internal account client")
	}

	return c.processSubEx([]byte(subject), nil, []byte(sid), cb, false, false, ri)
}

// This will add an account subscription that matches the "from" from a service import entry.
func (a *Account) addServiceImportSub(si *serviceImport) error {
	a.mu.Lock()
	c := a.internalClient()
	// This will happen in parsing when the account has not been properly setup.
	if c == nil {
		a.mu.Unlock()
		return nil
	}
	if si.sid != nil {
		a.mu.Unlock()
		return fmt.Errorf("duplicate call to create subscription for service import")
	}

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Ensure the account is added to the server (srv.AddAccount) before creating service imports.
  2. In tests, create the account via server APIs (s.AddAccount) rather than bare struct construction.
  3. Retry the operation after account setup completes.

Example fix

// before
acc := &Account{Name: "A"}
acc.AddServiceImport(dest, "req", "help") // no internal client
// after
acc, _ := s.AddAccount(NewAccount("A"))
acc.AddServiceImport(dest, "req", "help")
Defensive patterns

Strategy: validation

Validate before calling

if acc.internalClient() == nil {
    return errors.New("account not attached to server")
}

Try / catch

if _, err := acc.subscribeInternal(si, cb); err != nil {
    if strings.Contains(err.Error(), "no internal account client") {
        // add account to server first, then retry
    }
}

Prevention

When it happens

Trigger: Calling subscribeInternal (used by service import internals, e.g. during import parsing) while the account's internal client has not been initialized.

Common situations: Loading/parsing account imports from claims before the account is attached to a running server; test harnesses that construct Account structs manually without sl := NewAccount.

Related errors


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