{"record":{"id":"297c62867dcd61f0","repo":"hashicorp/nomad","slug":"check-q-is-missing-a-port","errorCode":null,"errorMessage":"check %q is missing a port","messagePattern":"check %q is missing a port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":8546,"sourceCode":"\t\t\t}\n\n\t\t\tif check.AddressMode == AddressModeAllocIPv6 {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"check %q cannot use address_mode=\\\"alloc_ipv6\\\", only checks defined in a \\\"group\\\" service block can use this mode\", service.Name))\n\t\t\t}\n\n\t\t\tif !check.RequiresPort() {\n\t\t\t\t// No need to continue validating check if it doesn't need a port\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\teffectivePort := check.PortLabel\n\t\t\tif effectivePort == \"\" {\n\t\t\t\t// Inherits from service\n\t\t\t\teffectivePort = service.PortLabel\n\t\t\t}\n\n\t\t\tif effectivePort == \"\" {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"check %q is missing a port\", check.Name))\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tisNumeric := false\n\t\t\tportNumber, err := strconv.Atoi(effectivePort)\n\t\t\tif err == nil {\n\t\t\t\tisNumeric = true\n\t\t\t}\n\n\t\t\t// Numeric ports are fine for address_mode = \"driver\"\n\t\t\tif check.AddressMode == \"driver\" && isNumeric {\n\t\t\t\tif portNumber <= 0 {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"check %q has invalid numeric port %d\", check.Name, portNumber))\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif isNumeric {","sourceCodeStart":8528,"sourceCodeEnd":8564,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L8528-L8564","documentation":"A check that requires a port (RequiresPort, e.g. tcp/http checks) ended up with an empty effective port: neither the check's own port field nor the parent service's port label supplied one. Nomad derives the effective port from the check first, then inherits the service PortLabel, and errors when both are empty.","triggerScenarios":"Submitting a job where a check of a port-requiring type (tcp/http) omits its `port` while the parent service has an empty port_label (e.g. address_mode=\"driver\" with a numeric service port); check.RequiresPort() returns true and effectivePort resolves to \"\".","commonSituations":"Using a numeric port on the service without a labeled port so the check cannot inherit a label; forgetting the check `port` attribute when the service declares one; script/grpc-less check types misconfigured without ports.","solutions":["Add `port = \"<label>\"` to the check block referencing a group network port label.","Ensure the parent service has a valid port_label the check can inherit.","If the check genuinely needs no port (e.g. some script checks), switch the check type to one where RequiresPort() is false.","Run `nomad job validate` to catch missing ports pre-submit."],"exampleFix":"// before\nservice {\n  name = \"api\"\n  port = \"http\"\n  check { name = \"live\"; type = \"http\"; path = \"/health\" }\n}\n\n// after\nservice {\n  name = \"api\"\n  port = \"http\"\n  check { name = \"live\"; type = \"http\"; path = \"/health\"; port = \"http\" }\n}","handlingStrategy":"validation","validationCode":"for _, svc := range allServices {\n  for _, c := range svc.Checks {\n    if c.RequiresPort() && c.Port == \"\" && svc.PortLabel == \"\" {\n      return fmt.Errorf(\"service %q: check %q has no port and service has no port_label\", svc.Name, c.Name)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always give port-requiring checks (tcp/http) an explicit port label","Ensure the parent service has a non-empty port_label so checks can inherit","Define named ports in the group network block and reference them consistently"],"tags":["nomad","health-check","port","service-validation"],"backgroundTag":"missing-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"}