{"record":{"id":"e079317ac14cae57","repo":"grpc/grpc-go","slug":"duplicated-name","errorCode":null,"errorMessage":"duplicated name","messagePattern":"duplicated name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service_config.go","lineNumber":129,"sourceCode":"\t// between 0 and maxTokens.\n\t//\n\t// This field is required and must be greater than zero.\n\tMaxTokens float64\n\t// The amount of tokens to add on each successful RPC. Typically this will\n\t// be some number between 0 and 1, e.g., 0.1.\n\t//\n\t// This field is required and must be greater than zero. Up to 3 decimal\n\t// places are supported.\n\tTokenRatio float64\n}\n\ntype jsonName struct {\n\tService string\n\tMethod  string\n}\n\nvar (\n\terrDuplicatedName             = errors.New(\"duplicated name\")\n\terrEmptyServiceNonEmptyMethod = errors.New(\"cannot combine empty 'service' and non-empty 'method'\")\n)\n\nfunc (j jsonName) generatePath() (string, error) {\n\tif j.Service == \"\" {\n\t\tif j.Method != \"\" {\n\t\t\treturn \"\", errEmptyServiceNonEmptyMethod\n\t\t}\n\t\treturn \"\", nil\n\t}\n\tres := \"/\" + j.Service + \"/\"\n\tif j.Method != \"\" {\n\t\tres += j.Method\n\t}\n\treturn res, nil\n}\n\n// TODO(lyuxuan): delete this struct after cleaning up old service config implementation.","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/service_config.go#L111-L147","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n{\n  \"methodConfig\": [\n    { \"name\": [{\"service\":\"svc\",\"method\":\"M\"}], \"retryPolicy\": {...} },\n    { \"name\": [{\"service\":\"svc\",\"method\":\"M\"}], \"retryPolicy\": {...} }\n  ]\n}\n\n// after - merge into one entry\n{\n  \"methodConfig\": [\n    { \"name\": [{\"service\":\"svc\",\"method\":\"M\"}], \"retryPolicy\": {...} }\n  ]\n}","handlingStrategy":"validation","validationCode":"func validateServiceConfig(raw []byte) error {\n    var sc map[string]any\n    if err := json.Unmarshal(raw, &sc); err != nil { return err }\n    seen := map[string]bool{}\n    for _, mc := range sc[\"methodConfig\"].([]any) {\n        for _, n := range mc.(map[string]any)[\"name\"].([]any) {\n            nm := n.(map[string]any)\n            path := \"/\" + nm[\"service\"].(string) + \"/\" + nm[\"method\"].(string)\n            if seen[path] { return fmt.Errorf(\"duplicate method %s\", path) }\n            seen[path] = true\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"pr := scparser.Parse(raw)\nif pr.Err != nil {\n    if strings.Contains(pr.Err.Error(), \"duplicated name\") {\n        log.Printf(\"service config has duplicate method: %v\", pr.Err)\n    }\n}","preventionTips":["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."],"tags":["go","grpc","service-config","validation"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}