{"record":{"id":"0e6ab50616037535","repo":"hashicorp/nomad","slug":"error-parsing-port-q-from-check-q-v","errorCode":null,"errorMessage":"error parsing port %q from check %q: %v","messagePattern":"error parsing port %q from check %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/consul/service_client.go","lineNumber":1273,"sourceCode":"\t\t\t_ = c.agentAPI.ServiceDeregisterOpts(legacyID, nil)\n\t\t}\n\n\t\tfor _, check := range service.Checks {\n\t\t\tcheckID := MakeCheckID(id, check)\n\t\t\tif check.Type == structs.ServiceCheckScript {\n\t\t\t\treturn fmt.Errorf(\"service %q contains invalid check: agent checks do not support scripts\", service.Name)\n\t\t\t}\n\t\t\tcheckHost, checkPort := serviceReg.Address, serviceReg.Port\n\t\t\tif check.PortLabel != \"\" {\n\t\t\t\t// Unlike tasks, agents don't use port labels. Agent ports are\n\t\t\t\t// stored directly in the PortLabel.\n\t\t\t\thost, rawport, err := net.SplitHostPort(check.PortLabel)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error parsing port label %q from check %q: %v\", service.PortLabel, check.Name, err)\n\t\t\t\t}\n\t\t\t\tport, err := strconv.Atoi(rawport)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error parsing port %q from check %q: %v\", rawport, check.Name, err)\n\t\t\t\t}\n\t\t\t\tcheckHost, checkPort = host, port\n\t\t\t}\n\t\t\tcheckReg, err := createCheckReg(id, checkID, check, checkHost, checkPort, \"\")\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to add check %q: %v\", check.Name, err)\n\t\t\t}\n\t\t\tops.regChecks = append(ops.regChecks, checkReg)\n\t\t}\n\t}\n\n\t// Don't bother committing agent checks if we're already shutting down\n\tc.agentLock.Lock()\n\tdefer c.agentLock.Unlock()\n\tselect {\n\tcase <-c.shutdownCh:\n\t\treturn nil\n\tdefault:","sourceCodeStart":1255,"sourceCodeEnd":1291,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/consul/service_client.go#L1255-L1291","documentation":"After splitting the check's PortLabel, the raw port string is converted with strconv.Atoi. When the host portion after the colon is not a numeric port (or is out of the valid range), Atoi fails and registration of the agent service is aborted with this message, wrapping the conversion error.","triggerScenarios":"A check PortLabel like '127.0.0.1:http' or '127.0.0.1:4646x' — SplitHostPort succeeds but the port component is non-numeric, so strconv.Atoi(rawport) errors and the wrapped message is returned.","commonSituations":"Using a service/port name instead of a number in an agent check port label; typo in the port; templating that left a placeholder like '${port}' unexpanded.","solutions":["Replace the non-numeric port with the actual numeric port in the check PortLabel (e.g. '127.0.0.1:4646')","Check the wrapped Atoi error text for the offending value and fix typos","If the port comes from a template, ensure the value is interpolated to a plain integer before the agent config loads","Prefer omitting port_label so the check uses the service's registered port"],"exampleFix":"// before\nport_label = \"127.0.0.1:http\"\n// after\nport_label = \"127.0.0.1:4646\"","handlingStrategy":"validation","validationCode":"if _, port, err := net.SplitHostPort(check.PortLabel); err != nil {\n  // split failed\n} else if _, convErr := strconv.Atoi(port); convErr != nil {\n  return fmt.Errorf(\"check %q port %q is not numeric\", check.Name, port)\n}","typeGuard":"func isNumericPort(label string) bool {\n  _, port, err := net.SplitHostPort(label)\n  if err != nil { return false }\n  n, err := strconv.Atoi(port)\n  return err == nil && n > 0 && n <= 65535\n}","tryCatchPattern":null,"preventionTips":["Use only numeric ports in agent check port labels","Resolve service/port names to numbers before config load","Beware unexpanded templates like ${port} in config","Validate range 1-65535"],"tags":["consul","nomad","port","strconv"],"backgroundTag":"invalid-port-label","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}