{"record":{"id":"3625e24ba2fa60c1","repo":"hashicorp/nomad","slug":"service-s-is-connect-native-and-requires-setting-3625e2","errorCode":null,"errorMessage":"Service %s is Connect Native and requires setting the port","messagePattern":"Service (.+?) is Connect Native and requires setting the port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/services.go","lineNumber":900,"sourceCode":"\tdefault:\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Service %s kind must be one of consul service kind or empty\", s.Name))\n\t}\n\n\t// check connect\n\tif s.Connect != nil {\n\t\tif err := s.Connect.Validate(); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t}\n\n\t\t// if service is connect native, service task must be set (which may\n\t\t// happen implicitly in a job mutation if there is only one task)\n\t\tif s.Connect.IsNative() && len(s.TaskName) == 0 {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Service %s is Connect Native and requires setting the task\", s.Name))\n\t\t}\n\n\t\t// if service is connect native a port must be set on the service or consul will reject it\n\t\tif s.Connect.IsNative() && s.PortLabel == \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Service %s is Connect Native and requires setting the port\", s.Name))\n\t\t}\n\t}\n}\n\n// validateNomadService performs validation on a service which is using the\n// nomad provider.\nfunc (s *Service) validateNomadService(mErr *multierror.Error) {\n\t// check checks\n\tfor _, c := range s.Checks {\n\t\t// validate the check port\n\t\tif err := s.validateCheckPort(c); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\tcontinue\n\t\t}\n\n\t\t// validate the nomad check\n\t\tif err := c.validateNomad(); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, err)","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/services.go#L882-L918","documentation":"A Connect Native service must have a port label on the service stanza; Consul rejects native registrations without a port. validateConsulService enforces this when Connect.IsNative() is true and s.PortLabel is empty.","triggerScenarios":"A Connect Native service (connect stanza with native usage) whose service stanza has no `port` field and whose check/port configuration leaves PortLabel empty.","commonSituations":"Writing Connect Native services without a port because the app listens on a Unix socket or doesn't need inbound traffic; copying sidecar-based examples that omit ports.","solutions":["Add `port = \"<label>\"` to the service stanza, matching a port defined in the task's network stanza.","Ensure the task network stanza declares the referenced port.","If no inbound port is truly needed, keep the port set anyway — Consul requires it for native services."],"exampleFix":"// before\nservice {\n  name = \"native-svc\"\n  task = \"app\"\n  connect { sidecar_service {} }\n}\n// after\nservice {\n  name = \"native-svc\"\n  task = \"app\"\n  port = \"http\"\n  connect { sidecar_service {} }\n}","handlingStrategy":"validation","validationCode":"if svc.Connect != nil && svc.Connect.IsNative() && svc.PortLabel == \"\" {\n  return fmt.Errorf(\"connect-native service %q must set port\", svc.Name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair connect-native services with a port label from the task network stanza","Declare the referenced port in the task's network block","Run `nomad job validate` in CI on every job change"],"tags":["nomad","consul-connect","connect-native","port"],"backgroundTag":"connect-native-missing-port","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"}