grpc/grpc-go · error
duplicated name
Error message
duplicated name
What it means
errDuplicatedName (service_config.go:129) is returned in a serviceconfig.ParseResult when two methodConfig entries in a service config resolve to the same /Service/Method path. gRPC requires each method path to appear at most once, so the parser records the duplicate as a parse error. The collision is detected at service_config.go:250-253.
Source
Thrown at service_config.go:129
// between 0 and maxTokens.
//
// This field is required and must be greater than zero.
MaxTokens float64
// The amount of tokens to add on each successful RPC. Typically this will
// be some number between 0 and 1, e.g., 0.1.
//
// This field is required and must be greater than zero. Up to 3 decimal
// places are supported.
TokenRatio float64
}
type jsonName struct {
Service string
Method string
}
var (
errDuplicatedName = errors.New("duplicated name")
errEmptyServiceNonEmptyMethod = errors.New("cannot combine empty 'service' and non-empty 'method'")
)
func (j jsonName) generatePath() (string, error) {
if j.Service == "" {
if j.Method != "" {
return "", errEmptyServiceNonEmptyMethod
}
return "", nil
}
res := "/" + j.Service + "/"
if j.Method != "" {
res += j.Method
}
return res, nil
}
// TODO(lyuxuan): delete this struct after cleaning up old service config implementation.View on GitHub (pinned to 03255a9237)
Solutions
- Inspect the service config JSON and deduplicate methodConfig name entries so each /Service/Method path is unique.
- If using a control plane, fix the policy generation logic that emits overlapping entries.
- Validate the config with a schema/uniq check before publishing to service discovery.
- Remove bare service-name entries that overlap explicit method entries.
Example fix
// before
{
"methodConfig": [
{ "name": [{"service":"svc","method":"M"}], "retryPolicy": {...} },
{ "name": [{"service":"svc","method":"M"}], "retryPolicy": {...} }
]
}
// after - merge into one entry
{
"methodConfig": [
{ "name": [{"service":"svc","method":"M"}], "retryPolicy": {...} }
]
} Defensive patterns
Strategy: validation
Validate before calling
func validateServiceConfig(raw []byte) error {
var sc map[string]any
if err := json.Unmarshal(raw, &sc); err != nil { return err }
seen := map[string]bool{}
for _, mc := range sc["methodConfig"].([]any) {
for _, n := range mc.(map[string]any)["name"].([]any) {
nm := n.(map[string]any)
path := "/" + nm["service"].(string) + "/" + nm["method"].(string)
if seen[path] { return fmt.Errorf("duplicate method %s", path) }
seen[path] = true
}
}
return nil
} Try / catch
pr := scparser.Parse(raw)
if pr.Err != nil {
if strings.Contains(pr.Err.Error(), "duplicated name") {
log.Printf("service config has duplicate method: %v", pr.Err)
}
} Prevention
- Deduplicate methodConfig entries before publishing.
- Validate generated service configs in CI before they reach service discovery.
- Audit control-plane policy merge logic for overlapping method paths.
When it happens
Trigger: A service config JSON whose methodConfig[].name lists the same service+method twice, or two name blocks that generate the same path (e.g. a bare service name matching an earlier service+method entry).
Common situations: Hand-edited service config with overlapping method rules; a control plane merging per-method policies that collide; renaming a service but leaving stale entries; wildcard/bare-name entries overlapping specific ones.
Related errors
- no error details for status with code OK
- rls: bad control channel service config %q: %v
- rls: stale_age is set, but max_age is not in route lookup co
- rls: cache_size_bytes must be set to a non-zero value: %+v
- rls: invalid childPolicy: entry %v does not contain exactly
AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07).
Data as JSON: /api/errors/e079317ac14cae57.
Report an issue: GitHub.