{"record":{"id":"04ce188a1e910b16","repo":"hashicorp/nomad","slug":"unable-to-get-address-for-service-q-v","errorCode":null,"errorMessage":"unable to get address for service %q: %v","messagePattern":"unable to get address for service %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/serviceregistration/nsd/nsd.go","lineNumber":376,"sourceCode":"func (s *ServiceRegistrationHandler) Shutdown() { close(s.shutDownCh) }\n\n// generateNomadServiceRegistration is a helper to build the Nomad specific\n// registration object on a per-service basis.\nfunc (s *ServiceRegistrationHandler) generateNomadServiceRegistration(\n\tserviceSpec *structs.Service, workload *serviceregistration.WorkloadServices) (*structs.ServiceRegistration, error) {\n\n\t// Service address modes default to auto.\n\taddrMode := serviceSpec.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\tserviceSpec.Address, addrMode, serviceSpec.PortLabel, workload.Networks,\n\t\tworkload.DriverNetwork, workload.Ports, workload.NetworkStatus)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get address for service %q: %v\", serviceSpec.Name, err)\n\t}\n\n\t// Build the tags to use for this registration which is a result of whether\n\t// this is a canary, or not.\n\tvar tags []string\n\n\tif workload.Canary && len(serviceSpec.CanaryTags) > 0 {\n\t\ttags = make([]string, len(serviceSpec.CanaryTags))\n\t\tcopy(tags, serviceSpec.CanaryTags)\n\t} else {\n\t\ttags = make([]string, len(serviceSpec.Tags))\n\t\tcopy(tags, serviceSpec.Tags)\n\t}\n\n\treturn &structs.ServiceRegistration{\n\t\tID:          serviceregistration.MakeAllocServiceID(workload.AllocInfo.AllocID, workload.Name(), serviceSpec),\n\t\tServiceName: serviceSpec.Name,\n\t\tNodeID:      s.cfg.NodeID,","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/serviceregistration/nsd/nsd.go#L358-L394","documentation":"generateNomadServiceRegistration in the Nomad service registration provider wraps any error from serviceregistration.GetAddress with this message naming the service. It is a wrapper: the root cause is one of the GetAddress failures (missing network status, bad port label, invalid mode, etc.), surfaced during RegisterWorkload.","triggerScenarios":"RegisterWorkload calls generateNomadServiceRegistration for a Nomad-provider service; GetAddress fails for that service spec (nil NetworkStatus with alloc mode, unknown/non-numeric port label, <=0 literal port, or unknown address mode), and the error is re-wrapped with the service name.","commonSituations":"Group/task service stanzas with misconfigured port or address_mode being registered at task start/update; checking client logs after a service registration failure and needing the wrapped inner error to diagnose.","solutions":["Read the wrapped %v cause to identify which GetAddress condition failed","Fix the service's port label to a declared port or positive numeric literal","Set a valid address_mode (host/driver/alloc) and ensure network status is available for alloc mode","Check workload.Networks/DriverNetwork/Ports/NetworkStatus inputs are populated as expected for the driver"],"exampleFix":"// before\nservice {\n  name = \"api\"\n  port = \"admin\"\n}\n// after\nservice {\n  name = \"api\"\n  port = \"http\"\n}","handlingStrategy":"try-catch","validationCode":"if err := validateServiceAddressing(serviceSpec, workload); err != nil {\n    return nil, fmt.Errorf(\"service %q pre-check failed: %w\", serviceSpec.Name, err)\n}","typeGuard":"func addressResolvable(spec ServiceSpec, w Workload) bool {\n    return !(spec.AddressMode == \"alloc\" && w.NetworkStatus == nil) &&\n        (isNumericLiteral(spec.PortLabel) || portLabelExists(spec.PortLabel, w.Ports))\n}","tryCatchPattern":"reg, err := provider.RegisterWorkload(workload)\nif err != nil {\n    var svcName string\n    if m := regexp.MustCompile(`service \"([^\"]+)\"`).FindStringSubmatch(err.Error()); m != nil {\n        svcName = m[1]\n    }\n    logger.Error(\"nomad service registration failed\", \"service\", svcName, \"err\", err)\n    return err\n}","preventionTips":["Unwrap the %v cause to find the real GetAddress failure before changing config","Validate port labels and address modes in CI with nomad job validate","Log workload.NetworkStatus presence for drivers in use","Test service stanzas in dev with the same driver/network topology as production"],"tags":["nomad","service-registration","error-wrapping","configuration"],"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"}