{"record":{"id":"2afebe44ee5cc242","repo":"go-kratos/kratos","slug":"service-s-not-resolved-in-registry","errorCode":null,"errorMessage":"service %s not resolved in registry","messagePattern":"service (.+?) not resolved in registry","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"contrib/registry/consul/registry.go","lineNumber":162,"sourceCode":"// GetService return service by name\nfunc (r *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error) {\n\tr.lock.RLock()\n\tset := r.registry[name]\n\tr.lock.RUnlock()\n\n\tgetRemote := func() []*registry.ServiceInstance {\n\t\tservices, _, err := r.cli.Service(ctx, name, 0, true)\n\t\tif err == nil && len(services) > 0 {\n\t\t\treturn services\n\t\t}\n\t\treturn nil\n\t}\n\n\tif set == nil {\n\t\tif s := getRemote(); len(s) > 0 {\n\t\t\treturn s, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"service %s not resolved in registry\", name)\n\t}\n\tss, _ := set.services.Load().([]*registry.ServiceInstance)\n\tif ss == nil {\n\t\tif s := getRemote(); len(s) > 0 {\n\t\t\treturn s, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"service %s not found in registry\", name)\n\t}\n\treturn ss, nil\n}\n\n// ListServices return service list.\nfunc (r *Registry) ListServices() (allServices map[string][]*registry.ServiceInstance, err error) {\n\tr.lock.RLock()\n\tdefer r.lock.RUnlock()\n\tallServices = make(map[string][]*registry.ServiceInstance)\n\tfor name, set := range r.registry {\n\t\tss, _ := set.services.Load().([]*registry.ServiceInstance)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/contrib/registry/consul/registry.go#L144-L180","documentation":"Consul registry GetService: the service name has no local watch set and a live Consul query (with health filtering) returned no instances, so resolution fails with 'not resolved in registry'. It means the name is unknown to Consul right now — not registered, all health checks critical, wrong datacenter/namespace, or ACL-filtered.","triggerScenarios":"Calling GetService(ctx, name) on the Consul registry where the watch set is nil (never watched locally) and the r.cli.Service query returns zero healthy instances.","commonSituations":"Cold start with the consumer up before the provider registers; provider crashed; health-check endpoint misconfigured (wrong path/port); typo'd service name; datacenter or namespace mismatch.","solutions":["Confirm the provider is registered and its health checks are passing in Consul (catalog/UI)","Double-check the exact service name and Consul datacenter/namespace/ACL settings on both sides","Retry with backoff — consumers frequently start before providers register","Fix the provider's health-check definition if checks are critical"],"exampleFix":"# before\n$ consul catalog services   # user-service absent or checks critical\n\n# after\n$ kubectl scale deploy/user --replicas=1\n$ consul catalog services   # user-service present, health passing","handlingStrategy":"retry","validationCode":"// pre-flight: confirm the name resolves before serving traffic\nsvcs, _, err := consulClient.Health().Service(\"user-service\", \"\", true, nil)\nif err != nil || len(svcs) == 0 {\n    return fmt.Errorf(\"user-service not healthy in consul: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < maxAttempts; attempt++ {\n    ins, err := reg.GetService(ctx, name)\n    if err == nil {\n        return ins\n    }\n    if strings.Contains(err.Error(), \"not resolved in registry\") {\n        time.Sleep(backoff(attempt)) // provider may still be registering\n        continue\n    }\n    return nil, err\n}","preventionTips":["Start providers before consumers, or add startup retries with backoff","Monitor Consul health checks and alert on critical","Double-check service names, datacenters, and ACLs in config"],"tags":["consul","registry","service-discovery","health-check","go"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}