hashicorp/nomad · error

unable to get address for service

Error message

unable to get address for service %q: %v

What it means

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.

Solutions

  1. Fix the service's port_label to match a port declared in the task group network block
  2. Set a supported address_mode ('auto', 'host', or 'alloc' as applicable) or remove it so 'auto' applies
  3. If using address_mode = 'driver', confirm the driver provides a DriverNetwork, else switch to 'host'/'alloc'
  4. Run `nomad job inspect`/plan output and verify the resolved network block contains the referenced port

Example fix

// before
service {
  name = "api"
  port = "htpp" // typo
}
// after
network {
  port "http" {}
}
service {
  name = "api"
  port = "http"
}
Defensive patterns

Strategy: validation

Validate before calling

// Ensure referenced port exists in the group network before submitting a job
func validateServicePort(s *structs.Service, ports map[string]structs.Port) error {
  if s.PortLabel == "" { return nil }
  if _, ok := ports[s.PortLabel]; !ok {
    return fmt.Errorf("service %q references undeclared port %q", s.Name, s.PortLabel)
  }
  return nil
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/8bc83bdb41a9a595. Report an issue: GitHub.

Appendix: source

Thrown at command/agent/consul/service_client.go:1334

	// Get the services ID
	id := serviceregistration.MakeAllocServiceID(workload.AllocInfo.AllocID, workload.Name(), service)
	sreg := &serviceregistration.ServiceRegistration{
		ServiceID:     id,
		CheckIDs:      make(map[string]struct{}, len(service.Checks)),
		CheckOnUpdate: make(map[string]string, len(service.Checks)),
	}

	// Service address modes default to auto
	addrMode := service.AddressMode
	if addrMode == "" {
		addrMode = structs.AddressModeAuto
	}

	// Determine the address to advertise based on the mode
	ip, port, err := serviceregistration.GetAddress(
		service.Address, addrMode, service.PortLabel, workload.Networks, workload.DriverNetwork, workload.Ports, workload.NetworkStatus)
	if err != nil {
		return nil, fmt.Errorf("unable to get address for service %q: %v", service.Name, err)
	}

	// Determine whether to use tags or canary_tags
	var tags []string
	if workload.Canary && len(service.CanaryTags) > 0 {
		tags = make([]string, len(service.CanaryTags))
		copy(tags, service.CanaryTags)
	} else {
		tags = make([]string, len(service.Tags))
		copy(tags, service.Tags)
	}

	// newConnect returns (nil, nil) if there's no Connect-enabled service.
	connect, err := newConnect(id, workload.AllocInfo, service.Name, service.Connect, workload.Networks, workload.Ports)
	if err != nil {
		return nil, fmt.Errorf("invalid Consul Connect configuration for service %q: %v", service.Name, err)
	}

View on GitHub (pinned to 482b49bf1a)