{"record":{"id":"8bc83bdb41a9a595","repo":"hashicorp/nomad","slug":"unable-to-get-address-for-service-q-v-8bc83b","errorCode":null,"errorMessage":"unable to get address for service %q: %v","messagePattern":"unable to get address for service %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/consul/service_client.go","lineNumber":1334,"sourceCode":"\t// Get the services ID\n\tid := serviceregistration.MakeAllocServiceID(workload.AllocInfo.AllocID, workload.Name(), service)\n\tsreg := &serviceregistration.ServiceRegistration{\n\t\tServiceID:     id,\n\t\tCheckIDs:      make(map[string]struct{}, len(service.Checks)),\n\t\tCheckOnUpdate: make(map[string]string, len(service.Checks)),\n\t}\n\n\t// Service address modes default to auto\n\taddrMode := service.AddressMode\n\tif addrMode == \"\" {\n\t\taddrMode = structs.AddressModeAuto\n\t}\n\n\t// Determine the address to advertise based on the mode\n\tip, port, err := serviceregistration.GetAddress(\n\t\tservice.Address, addrMode, service.PortLabel, workload.Networks, workload.DriverNetwork, workload.Ports, workload.NetworkStatus)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get address for service %q: %v\", service.Name, err)\n\t}\n\n\t// Determine whether to use tags or canary_tags\n\tvar tags []string\n\tif workload.Canary && len(service.CanaryTags) > 0 {\n\t\ttags = make([]string, len(service.CanaryTags))\n\t\tcopy(tags, service.CanaryTags)\n\t} else {\n\t\ttags = make([]string, len(service.Tags))\n\t\tcopy(tags, service.Tags)\n\t}\n\n\t// newConnect returns (nil, nil) if there's no Connect-enabled service.\n\tconnect, err := newConnect(id, workload.AllocInfo, service.Name, service.Connect, workload.Networks, workload.Ports)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid Consul Connect configuration for service %q: %v\", service.Name, err)\n\t}\n","sourceCodeStart":1316,"sourceCodeEnd":1352,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/consul/service_client.go#L1316-L1352","documentation":"Before building a Consul service registration for a task workload, Nomad resolves the advertised address/port via serviceregistration.GetAddress using the service's address, address_mode, and port_label against workload networks. Any failure there (unresolvable mode, unknown port label, no matching network) is wrapped in this message and registration aborts, returning nil registration.","triggerScenarios":"getRegistrations (task service registration path) calls serviceregistration.GetAddress and it errors: port_label does not exist in workload.Ports/Networks, address_mode 'driver' with no DriverNetwork, 'host' mode with no static host port, or no network status present.","commonSituations":"Service references a port label typo'd or removed from the group's network block; address_mode = 'driver' on a driver that doesn't expose a network; consul connect services before network is assigned; IPv6/host_network misconfig.","solutions":["Fix the service's port_label to match a port declared in the task group network block","Set a supported address_mode ('auto', 'host', or 'alloc' as applicable) or remove it so 'auto' applies","If using address_mode = 'driver', confirm the driver provides a DriverNetwork, else switch to 'host'/'alloc'","Run `nomad job inspect`/plan output and verify the resolved network block contains the referenced port"],"exampleFix":"// before\nservice {\n  name = \"api\"\n  port = \"htpp\" // typo\n}\n// after\nnetwork {\n  port \"http\" {}\n}\nservice {\n  name = \"api\"\n  port = \"http\"\n}","handlingStrategy":"validation","validationCode":"// Ensure referenced port exists in the group network before submitting a job\nfunc validateServicePort(s *structs.Service, ports map[string]structs.Port) error {\n  if s.PortLabel == \"\" { return nil }\n  if _, ok := ports[s.PortLabel]; !ok {\n    return fmt.Errorf(\"service %q references undeclared port %q\", s.Name, s.PortLabel)\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always declare service port labels in the task-group network block","Use address_mode='auto' unless you specifically need host/driver","Check `nomad job plan` output for address resolution before applying","Ensure drivers requiring address_mode='driver' actually provide driver networks"],"tags":["consul","nomad","address-mode","port-label"],"backgroundTag":"service-address-resolution-failed","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"}