{"record":{"id":"0b2b954507b1f963","repo":"nats-io/nats-server","slug":"fetching-jwt-timed-out","errorCode":null,"errorMessage":"fetching jwt timed out","messagePattern":"fetching jwt timed out","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/accounts.go","lineNumber":4773,"sourceCode":"\t\t// Use the first valid response if there is still interest or\n\t\t// one of the empty responses to signal that it was not found.\n\t\tif _, ok := replies[replySubj]; ok {\n\t\t\tselect {\n\t\t\tcase respC <- clone:\n\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t}\n\ts.sendInternalMsg(accountLookupRequest, replySubj, nil, []byte{})\n\tquit := s.quitCh\n\ts.mu.Unlock()\n\tvar err error\n\tvar theJWT string\n\tselect {\n\tcase <-quit:\n\t\terr = errors.New(\"fetching jwt failed due to shutdown\")\n\tcase <-time.After(timeout):\n\t\terr = errors.New(\"fetching jwt timed out\")\n\tcase m := <-respC:\n\t\tif len(m) == 0 {\n\t\t\terr = errors.New(\"account jwt not found\")\n\t\t} else if err = res.Store(name, string(m)); err == nil {\n\t\t\ttheJWT = string(m)\n\t\t}\n\t}\n\ts.mu.Lock()\n\tdelete(replies, replySubj)\n\ts.mu.Unlock()\n\tclose(respC)\n\treturn theJWT, err\n}\n\nfunc NewCacheDirAccResolver(path string, limit int64, ttl time.Duration, opts ...DirResOption) (*CacheDirAccResolver, error) {\n\tif limit <= 0 {\n\t\tlimit = 1_000\n\t}","sourceCodeStart":4755,"sourceCodeEnd":4791,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/accounts.go#L4755-L4791","documentation":"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.","triggerScenarios":"Calling Connz with ConnzOptions{Sort: ByStop, State: ConnOpen} (or ConnInit/ConnAll/etc.); HTTP GET /connz?sort=stop&state=open.","commonSituations":"Monitoring dashboards that pair a 'stopped at' sort with an 'open connections' view; query strings assembled independently for sort and state parameters.","solutions":["Set opts.State to ConnClosed when sorting by ByStop (or ByReason)","Remove the ByStop sort option if you need open connections; sort by idle/start instead","Validate the sort/state combination in the dashboard before calling Connz"],"exampleFix":"// before\nconnz, err := srv.Connz(&ConnzOptions{Sort: ByStop, State: ConnOpen})\n// after\nconnz, err := srv.Connz(&ConnzOptions{Sort: ByStop, State: ConnClosed})","handlingStrategy":"validation","validationCode":"if sort == server.ByStop || sort == server.ByReason {\n    state = server.ConnClosed // required combination\n}\nconnz, err := srv.Connz(&server.ConnzOptions{Sort: sort, State: state})","typeGuard":null,"tryCatchPattern":"connz, err := srv.Connz(&ConnzOptions{Sort: ByStop, State: ConnClosed})\nif err != nil && strings.Contains(err.Error(), \"only valid on closed connections\") {\n    // fall back to sorting open connections by start/idle instead\n}","preventionTips":["Couple ByStop/ByReason sorts with ConnClosed state in dashboard logic","Validate sort+state combinations together, not as independent params","Offer a different sort for live-connection views (idle, start, subs)"],"tags":["monitoring","http","connz","validation"],"backgroundTag":"invalid-sort-state-combination","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}