nats-io/nats-server · error

fetching jwt timed out

Error message

fetching jwt timed out

What it means

Connz rejects Sort=ByStop (and ByReason analogously) when the state filter is not ConnClosed, because stopped-at timestamps only exist for closed connections. Sorting open connections by stop time is meaningless, so the request is refused with this error. Note there is a parallel 'sort by reason only valid on closed connections' error for ByReason.

Source

Thrown at server/accounts.go:4773

		// Use the first valid response if there is still interest or
		// one of the empty responses to signal that it was not found.
		if _, ok := replies[replySubj]; ok {
			select {
			case respC <- clone:
			default:
			}
		}
	}
	s.sendInternalMsg(accountLookupRequest, replySubj, nil, []byte{})
	quit := s.quitCh
	s.mu.Unlock()
	var err error
	var theJWT string
	select {
	case <-quit:
		err = errors.New("fetching jwt failed due to shutdown")
	case <-time.After(timeout):
		err = errors.New("fetching jwt timed out")
	case m := <-respC:
		if len(m) == 0 {
			err = errors.New("account jwt not found")
		} else if err = res.Store(name, string(m)); err == nil {
			theJWT = string(m)
		}
	}
	s.mu.Lock()
	delete(replies, replySubj)
	s.mu.Unlock()
	close(respC)
	return theJWT, err
}

func NewCacheDirAccResolver(path string, limit int64, ttl time.Duration, opts ...DirResOption) (*CacheDirAccResolver, error) {
	if limit <= 0 {
		limit = 1_000
	}

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Set opts.State to ConnClosed when sorting by ByStop (or ByReason)
  2. Remove the ByStop sort option if you need open connections; sort by idle/start instead
  3. Validate the sort/state combination in the dashboard before calling Connz

Example fix

// before
connz, err := srv.Connz(&ConnzOptions{Sort: ByStop, State: ConnOpen})
// after
connz, err := srv.Connz(&ConnzOptions{Sort: ByStop, State: ConnClosed})
Defensive patterns

Strategy: validation

Validate before calling

if sort == server.ByStop || sort == server.ByReason {
    state = server.ConnClosed // required combination
}
connz, err := srv.Connz(&server.ConnzOptions{Sort: sort, State: state})

Try / catch

connz, err := srv.Connz(&ConnzOptions{Sort: ByStop, State: ConnClosed})
if err != nil && strings.Contains(err.Error(), "only valid on closed connections") {
    // fall back to sorting open connections by start/idle instead
}

Prevention

When it happens

Trigger: Calling Connz with ConnzOptions{Sort: ByStop, State: ConnOpen} (or ConnInit/ConnAll/etc.); HTTP GET /connz?sort=stop&state=open.

Common situations: Monitoring dashboards that pair a 'stopped at' sort with an 'open connections' view; query strings assembled independently for sort and state parameters.

Understand the failure class

Related errors


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