{"record":{"id":"bbdb4cc14aab1bf0","repo":"nats-io/nats-server","slug":"no-internal-account-client","errorCode":null,"errorMessage":"no internal account client","messagePattern":"no internal account client","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/accounts.go","lineNumber":2251,"sourceCode":"\tif ic := a.internalClient(); ic != nil {\n\t\tic.processUnsub(sub.sid)\n\t}\n}\n\n// Creates internal subscription for service import responses.\nfunc (a *Account) subscribeServiceImportResponse(subject string) (*subscription, error) {\n\treturn a.subscribeInternalEx(subject, a.processServiceImportResponse, true)\n}\n\nfunc (a *Account) subscribeInternalEx(subject string, cb msgHandler, ri bool) (*subscription, error) {\n\ta.mu.Lock()\n\ta.isid++\n\tc, sid := a.internalClient(), strconv.FormatUint(a.isid, 10)\n\ta.mu.Unlock()\n\n\t// This will happen in parsing when the account has not been properly setup.\n\tif c == nil {\n\t\treturn nil, fmt.Errorf(\"no internal account client\")\n\t}\n\n\treturn c.processSubEx([]byte(subject), nil, []byte(sid), cb, false, false, ri)\n}\n\n// This will add an account subscription that matches the \"from\" from a service import entry.\nfunc (a *Account) addServiceImportSub(si *serviceImport) error {\n\ta.mu.Lock()\n\tc := a.internalClient()\n\t// This will happen in parsing when the account has not been properly setup.\n\tif c == nil {\n\t\ta.mu.Unlock()\n\t\treturn nil\n\t}\n\tif si.sid != nil {\n\t\ta.mu.Unlock()\n\t\treturn fmt.Errorf(\"duplicate call to create subscription for service import\")\n\t}","sourceCodeStart":2233,"sourceCodeEnd":2269,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/accounts.go#L2233-L2269","documentation":"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.","triggerScenarios":"Calling subscribeInternal (used by service import internals, e.g. during import parsing) while the account's internal client has not been initialized.","commonSituations":"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.","solutions":["Ensure the account is added to the server (srv.AddAccount) before creating service imports.","In tests, create the account via server APIs (s.AddAccount) rather than bare struct construction.","Retry the operation after account setup completes."],"exampleFix":"// before\nacc := &Account{Name: \"A\"}\nacc.AddServiceImport(dest, \"req\", \"help\") // no internal client\n// after\nacc, _ := s.AddAccount(NewAccount(\"A\"))\nacc.AddServiceImport(dest, \"req\", \"help\")","handlingStrategy":"validation","validationCode":"if acc.internalClient() == nil {\n    return errors.New(\"account not attached to server\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := acc.subscribeInternal(si, cb); err != nil {\n    if strings.Contains(err.Error(), \"no internal account client\") {\n        // add account to server first, then retry\n    }\n}","preventionTips":["Create accounts via s.AddAccount","Never construct Account structs manually in tests","Ensure account setup completes before imports"],"tags":["nats-server","account-setup","internal-client"],"backgroundTag":"account-not-initialized","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}