micro/go-micro · error · ErrNotFound

service not found

Error message

service not found

What it means

registry.ErrNotFound is the sentinel error returned by GetService (and lookups like next/serviceWithName/Load) when no service with the requested name exists in the registry. It is the library's contract for 'unknown service name'.

Source

Thrown at registry/registry.go:10

// Package registry is an interface for service discovery
package registry

import (
	"errors"
)

var (
	// Not found error when GetService is called.
	ErrNotFound = errors.New("service not found")
	// Watcher stopped error when watcher is stopped.
	ErrWatcherStopped = errors.New("watcher stopped")
)

// The registry provides an interface for service discovery
// and an abstraction over varying implementations
// {consul, etcd, zookeeper, ...}.
type Registry interface {
	Init(...Option) error
	Options() Options
	Register(*Service, ...RegisterOption) error
	Deregister(*Service, ...DeregisterOption) error
	GetService(string, ...GetOption) ([]*Service, error)
	ListServices(...ListOption) ([]*Service, error)
	Watch(...WatchOption) (Watcher, error)
	String() string
}

View on GitHub (pinned to 24529f1404)

Solutions

  1. Verify the exact service name matches what the server registered (check name, version, namespace)
  2. Compare with errors.Equal/== against registry.ErrNotFound and implement retry-with-backoff until the service appears
  3. Check the target service is running and successfully registered (inspect registry contents directly)
  4. Increase or verify TTL refresh/heartbeats so registrations don't expire

Example fix

// before
svc, err := registry.GetService("grettr") // typo, err not checked against sentinel
// after
if err == registry.ErrNotFound {
  time.Sleep(500 * time.Millisecond) // backoff and retry
  svc, err = registry.GetService("greeter")
}
Defensive patterns

Strategy: retry

Validate before calling

_, err := reg.GetService(name)
if err == registry.ErrNotFound {
  // service absent; wait or check registration before proceeding
}

Type guard

func isNotFound(err error) bool {
  return errors.Is(err, registry.ErrNotFound)
}

Try / catch

svc, err := reg.GetService("greeter")
if errors.Is(err, registry.ErrNotFound) {
  // retry with backoff or surface 'unknown service' to caller
}

Prevention

When it happens

Trigger: Calling registry.GetService("name") for a service never registered; calling after the service deregistered or its TTL/lease expired; registry cache missing the entry (e.g. cache not yet populated); tests calling Read/Load for a missing fixture service.

Common situations: Typo in the service name or mismatched namespace/environment prefixes; client started before the target service registered (startup race); etcd/consul entries evicted due to TTL expiry or network partition; switching registries between environments.

Related errors


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