{"record":{"id":"a7b6a43d40991bbf","repo":"nats-io/nats-server","slug":"jetstream-account-not-registered","errorCode":null,"errorMessage":"jetstream account not registered","messagePattern":"jetstream account not registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/jetstream.go","lineNumber":799,"sourceCode":"\t\t}\n\t\tgacc.mu.Unlock()\n\t\tif err := s.configJetStream(gacc, tq); err != nil {\n\t\t\treturn err\n\t\t}\n\t} else if err := s.configAllJetStreamAccounts(tq); err != nil {\n\t\treturn fmt.Errorf(\"Error enabling jetstream on configured accounts: %v\", err)\n\t}\n\treturn nil\n}\n\n// enableAllJetStreamServiceImportsAndMappings turns on all service imports and mappings for jetstream for this account.\nfunc (a *Account) enableAllJetStreamServiceImportsAndMappings() error {\n\ta.mu.RLock()\n\ts := a.srv\n\ta.mu.RUnlock()\n\n\tif s == nil {\n\t\treturn fmt.Errorf(\"jetstream account not registered\")\n\t}\n\n\tvar dstAccName string\n\tif sacc := s.SystemAccount(); sacc != nil {\n\t\tdstAccName = sacc.Name\n\t}\n\n\tif !a.serviceImportExists(dstAccName, jsAllAPI) {\n\t\t// Capture si so we can turn on implicit sharing with JetStream layer.\n\t\t// Make sure to set \"to\" otherwise will incur performance slow down.\n\t\tsi, err := a.addServiceImport(s.SystemAccount(), jsAllAPI, jsAllAPI, nil)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error setting up jetstream service imports for account: %v\", err)\n\t\t}\n\t\ta.mu.Lock()\n\t\tsi.share = true\n\t\ta.mu.Unlock()\n\t}","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/jetstream.go#L781-L817","documentation":"enableAllJetStreamServiceImportsAndMappings adds the JetStream API service import from the system account into this account so the account can reach $JS.API subjects. If the account's srv pointer is nil, the account is not (or no longer) registered with a running server, so there is no server context under which to create the import and this error is returned. It is an internal invariant check rather than a user-facing validation.","triggerScenarios":"Calling Account.EnableJetStream (or internally enableAllJetStreamServiceImportsAndMappings) on an account whose a.srv is nil - i.e. the account was created but never added to a running server, or was removed (account teardown) while JetStream setup still runs.","commonSituations":"Using an Account object after server shutdown or account removal; constructing an Account standalone in tests without AccountsAdd; a race where the account is being deleted concurrently with JetStream enablement.","solutions":["Register the account with a running server before enabling JetStream (pass it via Accounts in Options or call s.AddAccount).","Ensure the server is started and running before calling EnableJetStream on the account.","Guard against calling JetStream APIs during server shutdown/account removal in your code.","Check that you are not holding a stale *Account reference from before a server restart."],"exampleFix":"// before\nacc, _ := server.NewAccount(\"JS\")\nacc.EnableJetStream(nil, nil) // srv is nil -> error\n// after\nopts := server.DefaultOptions()\nopts.Accounts = []*server.Account{acc}\ns, _ := server.NewServer(opts)\ngo s.Start()\nacc.EnableJetStream(nil, nil) // registered, works","handlingStrategy":"validation","validationCode":"if acc == nil || !s.Running() {\n    return fmt.Errorf(\"account must be registered with a running server before JetStream setup\")\n}\nif _, err := s.LookupAccount(acc.Name); err != nil {\n    return fmt.Errorf(\"account %s not registered: %w\", acc.Name, err)\n}","typeGuard":null,"tryCatchPattern":"if err := acc.EnableJetStream(limits, tq); err != nil {\n    if strings.Contains(err.Error(), \"not registered\") {\n        // re-add account to server and retry once\n    }\n    return err\n}","preventionTips":["Always add accounts via Options.Accounts or s.AddAccount before JetStream calls","Check s.Running() before any account-level JetStream API","Avoid holding account references across server restarts","In tests, start the server and wait for ReadyForConnections before touching accounts"],"tags":["jetstream","account-lifecycle","nats-server"],"backgroundTag":"account-not-registered","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}