{"record":{"id":"654ebf0e40e98b13","repo":"nats-io/nats-server","slug":"wrong-gateway","errorCode":null,"errorMessage":"wrong gateway","messagePattern":"wrong gateway","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":162,"sourceCode":"\tErrStreamImportDuplicate = errors.New(\"stream import already exists\")\n\n\t// ErrServiceImportAuthorization is returned when a service import is not authorized.\n\tErrServiceImportAuthorization = errors.New(\"service import not authorized\")\n\n\t// ErrImportFormsCycle is returned when an import would form a cycle.\n\tErrImportFormsCycle = errors.New(\"import forms a cycle\")\n\n\t// ErrCycleSearchDepth is returned when we have exceeded our maximum search depth..\n\tErrCycleSearchDepth = errors.New(\"search cycle depth exhausted\")\n\n\t// ErrClientOrRouteConnectedToGatewayPort represents an error condition when\n\t// a client or route attempted to connect to the Gateway port.\n\tErrClientOrRouteConnectedToGatewayPort = errors.New(\"attempted to connect to gateway port\")\n\n\t// ErrWrongGateway represents an error condition when a server receives a connect\n\t// request from a remote Gateway with a destination name that does not match the server's\n\t// Gateway's name.\n\tErrWrongGateway = errors.New(\"wrong gateway\")\n\n\t// ErrGatewayNameHasSpaces signals that the gateway name contains spaces, which is not allowed.\n\tErrGatewayNameHasSpaces = errors.New(\"gateway name cannot contain spaces\")\n\n\t// ErrNoSysAccount is returned when an attempt to publish or subscribe is made\n\t// when there is no internal system account defined.\n\tErrNoSysAccount = errors.New(\"system account not setup\")\n\n\t// ErrRevocation is returned when a credential has been revoked.\n\tErrRevocation = errors.New(\"credentials have been revoked\")\n\n\t// ErrServerNotRunning is used to signal an error that a server is not running.\n\tErrServerNotRunning = errors.New(\"server is not running\")\n\n\t// ErrServerNameHasSpaces signals that the server name contains spaces, which is not allowed.\n\tErrServerNameHasSpaces = errors.New(\"server name cannot contain spaces\")\n\n\t// ErrBadMsgHeader signals the parser detected a bad message header","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L144-L180","documentation":"ErrWrongGateway is returned when a server receives a gateway CONNECT from a remote gateway whose destination name does not match this server's configured gateway name. Gateway connections are paired by name; a mismatch means the remote peer dialed the wrong cluster or the gateway names are inconsistent across the topology. The sentinel is also the fixture for NewErrorCtx tests (TestErrCtx) showing errors can carry extra context while keeping the same Error() string.","triggerScenarios":"A remote gateway configured with a different `gateway.name` connects to this server's gateway port; gateways list URLs of a cluster whose name differs from the remote name given in `gateway.gateways`; symmetric gateway configs where local name is spelled differently on each side.","commonSituations":"Renaming a gateway in one cluster's config but not its peers; load balancer fronting two different gateway clusters; typos in the gateway name (case/spacing) between sites.","solutions":["Make `gateway { name }` identical on all servers meant to gateway to each other.","Check `gateway.gateways` entries: the `name` of each remote entry must match that cluster's configured gateway name.","After a rename, update every peer's config and rolling-restart the servers.","If gateways are intentionally different clusters, remove the wrong remote URL from the gateways list."],"exampleFix":"// before (mismatch)\n// clusterA: gateway { name: \"east\" } ; clusterB: gateway { name: \"west\" }, gateways: [{url: \"nats://east:7222\", name: \"wst\"}]\n// after\n// clusterB: gateway { name: \"west\", gateways: [{url: \"nats://east:7222\", name: \"east\"}] }","handlingStrategy":"validation","validationCode":"// Before deploying, assert every server's gateway.name and every remote entry name match:\n// for each config: gateway.name must equal the `name` field peers use in gateway.gateways[].","typeGuard":null,"tryCatchPattern":"if err := waitForGateway(); err != nil {\n    if errors.Is(err, ErrWrongGateway) {\n        // log local vs remote gateway names from config and abort peering\n    }\n}","preventionTips":["Generate gateway configs from a single source of truth so names cannot diverge.","After renaming a gateway, update all peers' gateways[] entries in the same change.","Verify peering with `nats server request NGW` or server logs after rollout.","Use DNS/hostnames consistently so one cluster is not accidentally fronted by another."],"tags":["nats","gateway","configuration-mismatch"],"backgroundTag":"wrong-gateway-name","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}