micro/go-micro · error

ErrIPNotFound

ErrIPNotFound

Error message

no IP address found, and explicit IP not provided

What it means

ErrIPNotFound is the exported sentinel in internal/util/addr returned by findIP when it cannot determine any usable local IP address — either no interface yields a usable address or the explicitly requested IP is not present on the host. Callers compare with errors.Is to detect this condition.

Source

Thrown at internal/util/addr/addr.go:12

// addr provides functions to retrieve local IP addresses from device interfaces.
package addr

import (
	"net"

	"github.com/pkg/errors"
)

var (
	// ErrIPNotFound no IP address found, and explicit IP not provided.
	ErrIPNotFound = errors.New("no IP address found, and explicit IP not provided")
)

// IsLocal checks whether an IP belongs to one of the device's interfaces.
func IsLocal(addr string) bool {
	// Extract the host
	host, _, err := net.SplitHostPort(addr)
	if err == nil {
		addr = host
	}

	if addr == "localhost" {
		return true
	}

	// Check against all local ips
	for _, ip := range IPs() {
		if addr == ip {
			return true

View on GitHub (pinned to 24529f1404)

Solutions

  1. Ensure at least one network interface has a valid non-loopback IPv4/IPv6 address (check `ip addr` / `ifconfig`).
  2. If an explicit IP is configured, correct it to an address actually assigned to the host.
  3. In containers, verify the network namespace has eth0 configured (e.g. proper Docker network or CNI setup).
  4. Handle the sentinel with errors.Is(err, addr.ErrIPNotFound) and fall back to a configured advertise address.

Example fix

// before
ip, err := addr.FindIP() // panics path: no interface match

// after
ip, err := addr.FindIP()
if errors.Is(err, addr.ErrIPNotFound) {
	ip = net.ParseIP(cfg.AdvertiseAddress) // explicit fallback
}
Defensive patterns

Strategy: fallback

Validate before calling

addrs, _ := net.InterfaceAddrs()
hasUsable := false
for _, a := range addrs {
	if ipn, ok := a.(*net.IPNet); ok && !ipn.IP.IsLoopback() && ipn.IP.To4() != nil {
		hasUsable = true
	}
}
if !hasUsable {
	log.Warn("no non-loopback IP; set explicit advertise address")
}

Type guard

func isIPNotFound(err error) bool {
	return errors.Is(err, addr.ErrIPNotFound)
}

Try / catch

ip, err := addr.FindIP()
if err != nil {
	if errors.Is(err, addr.ErrIPNotFound) {
		ip = net.ParseIP(os.Getenv("ADVERTISE_IP"))
	}
	if ip == nil {
		return fmt.Errorf("cannot determine host IP: %w", err)
	}
}

Prevention

When it happens

Trigger: Calling code that resolves the host IP (findIP, or utilities like ExtractHostPort/IsLocal paths that need an address) on a machine with no non-loopback interfaces, or requesting an explicit IP that is not assigned to any device interface.

Common situations: Running in minimal containers (scratch/distroless) missing net tools/interfaces; VMs or sandboxes with only loopback up; specifying an explicit IP env/config value that doesn't exist on the host; Docker/Kubernetes pods with unusual network setups.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/287da63b312d21d8. Report an issue: GitHub.