{"record":{"id":"bf7aedf96fca074b","repo":"nats-io/nats-server","slug":"duplicate-service-import-subject-q-previously-us","errorCode":null,"errorMessage":"duplicate service import subject %q, previously used in import for account %q, subject %q","messagePattern":"duplicate service import subject %q, previously used in import for account %q, subject %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/accounts.go","lineNumber":2167,"sourceCode":"\t}\n\n\tvar atrc bool\n\tdest.mu.RLock()\n\tse := dest.getServiceExport(to)\n\tif se != nil {\n\t\trt = se.respType\n\t\tlat = se.latency\n\t\tatrc = se.atrc\n\t}\n\tdestAccName := dest.Name\n\tdest.mu.RUnlock()\n\n\ta.mu.Lock()\n\tif a.imports.services == nil {\n\t\ta.imports.services = make(map[string][]*serviceImport)\n\t} else if dup := a.getServiceImportForAccountLocked(destAccName, from); dup != nil {\n\t\ta.mu.Unlock()\n\t\treturn nil, fmt.Errorf(\"duplicate service import subject %q, previously used in import for account %q, subject %q\",\n\t\t\tfrom, dup.acc.Name, dup.to)\n\t}\n\n\tif to == _EMPTY_ {\n\t\tto = from\n\t}\n\t// Check to see if we have a wildcard\n\tvar (\n\t\tusePub bool\n\t\ttr     *subjectTransform\n\t\terr    error\n\t)\n\n\tif subjectHasWildcard(to) {\n\t\t// If to and from match, then we use the published subject.\n\t\tif to == from {\n\t\t\tusePub = true\n\t\t} else {","sourceCodeStart":2149,"sourceCodeEnd":2185,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/accounts.go#L2149-L2185","documentation":"AddServiceImport detects a duplicate service import subject (server/accounts.go:2167). Each 'from' subject may only be used once per account for service imports; the error reports the previously registered account and subject.","triggerScenarios":"Calling AddServiceImport twice with the same 'from' subject on the same account, or reusing a 'from' subject already bound to another destination account.","commonSituations":"Redeploying services without cleaning up old imports; two services on different accounts mapped to the same local request subject.","solutions":["Use a unique 'from' subject for each service import.","Remove the existing service import before re-adding it.","Check for prior registration by inspecting the account's imports.services."],"exampleFix":"// before\nacc.AddServiceImport(destA, \"req\", \"help\")\nacc.AddServiceImport(destB, \"req\", \"help2\") // duplicate \"req\"\n// after\nacc.AddServiceImport(destB, \"req2\", \"help2\")","handlingStrategy":"validation","validationCode":"if dup := acc.getServiceImportForAccount(destName, from); dup != nil {\n    return fmt.Errorf(\"subject %s already imported\", from)\n}","typeGuard":null,"tryCatchPattern":"if _, err := acc.AddServiceImport(dest, from, to); err != nil {\n    if strings.Contains(err.Error(), \"duplicate service import\") {\n        // remove old import or choose new subject\n    }\n}","preventionTips":["Namespace 'from' subjects per service","Remove stale imports during redeploy","Keep a registry of used import subjects per account"],"tags":["nats-server","service-import","duplicate-subject"],"backgroundTag":"duplicate-service-import-subject","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}