{"record":{"id":"935b71948fc15432","repo":"nats-io/nats-server","slug":"attempted-to-connect-to-route-port","errorCode":null,"errorMessage":"attempted to connect to route port","messagePattern":"attempted to connect to route port","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":83,"sourceCode":"\tErrTooManyConnections = errors.New(\"maximum connections exceeded\")\n\n\t// ErrTooManyAccountConnections signals that an account has reached its maximum number of active\n\t// connections.\n\tErrTooManyAccountConnections = errors.New(\"maximum account active connections exceeded\")\n\n\t// ErrLeafNodeLoop signals a leafnode is trying to register for a cluster we already have registered.\n\tErrLeafNodeLoop = errors.New(\"leafnode loop detected\")\n\n\t// ErrTooManySubs signals a client that the maximum number of subscriptions per connection\n\t// has been reached.\n\tErrTooManySubs = errors.New(\"maximum subscriptions exceeded\")\n\n\t// ErrTooManySubTokens signals a client that the subject has too many tokens.\n\tErrTooManySubTokens = errors.New(\"subject has exceeded number of tokens limit\")\n\n\t// ErrClientConnectedToRoutePort represents an error condition when a client\n\t// attempted to connect to the route listen port.\n\tErrClientConnectedToRoutePort = errors.New(\"attempted to connect to route port\")\n\n\t// ErrClientConnectedToLeafNodePort represents an error condition when a client\n\t// attempted to connect to the leaf node listen port.\n\tErrClientConnectedToLeafNodePort = errors.New(\"attempted to connect to leaf node port\")\n\n\t// ErrLeafNodeHasSameClusterName represents an error condition when a leafnode is a cluster\n\t// and it has the same cluster name as the hub cluster.\n\tErrLeafNodeHasSameClusterName = errors.New(\"remote leafnode has same cluster name\")\n\n\t// ErrLeafNodeDisabled is when we disable leafnodes.\n\tErrLeafNodeDisabled = errors.New(\"leafnodes disabled\")\n\n\t// ErrConnectedToWrongPort represents an error condition when a connection is attempted\n\t// to the wrong listen port (for instance a LeafNode to a client port, etc...)\n\tErrConnectedToWrongPort = errors.New(\"attempted to connect to wrong port\")\n\n\t// ErrAccountExists is returned when an account is attempted to be registered\n\t// but already exists.","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L65-L101","documentation":"ErrClientConnectedToRoutePort indicates a client (which provided a 'lang' field in its CONNECT protocol) attempted to connect to the NATS cluster route listen port instead of the client port. ROUTE connections never send lang in CONNECT, so its presence identifies the connection as a normal client library connection to the wrong port. The server sends the error and closes the connection with WrongPort.","triggerScenarios":"Pointing a NATS client library (Go, Java, etc.) at nats://host:ROUTE_PORT. Specifically in route.go:3054, during route CONNECT processing, if the lang field is non-empty the server treats the connection as a client and returns this error.","commonSituations":"Configuration mistake: using the cluster/route port (e.g. 6222) instead of the client port (e.g. 4222) in the client's servers URL; copying the route URL from a cluster config into application config; port swaps after a config refactor.","solutions":["Point the client at the client listen port (the 'port' or default 4222), not the route port (default 6222)","Check the server config to confirm which port is 'port' vs 'cluster { port }'","Verify with environment/deployment config that the URL given to nats.Connect was not templated from the route address"],"exampleFix":"// before\nnc, err := nats.Connect(\"nats://nats-1:6222\") // route port\n// after\nnc, err := nats.Connect(\"nats://nats-1:4222\") // client port","handlingStrategy":"validation","validationCode":"u, err := url.Parse(natsURL)\nif err != nil { return err }\nif port := u.Port(); port == \"6222\" { return fmt.Errorf(\"%s is a route port; use the client port\", natsURL) }","typeGuard":"func isLikelyClientURL(natsURL string) bool {\n    u, err := url.Parse(natsURL)\n    return err == nil && u.Port() != \"6222\" && u.Port() != \"7422\"\n}","tryCatchPattern":"nc, err := nats.Connect(url)\nif err != nil && strings.Contains(err.Error(), \"route port\") {\n    log.Fatalf(\"wrong port in %q: use the client listen port\", url)\n}","preventionTips":["Never copy cluster route URLs into client configuration","Name config variables explicitly (NATS_CLIENT_URL vs NATS_ROUTE_URL)","Verify ports against the server config after topology changes"],"tags":["nats","configuration","wrong-port","client"],"backgroundTag":"wrong-port-connection","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}