{"record":{"id":"316bd5c908cbfedc","repo":"grpc/grpc-go","slug":"failed-to-create-child-policy-of-type-s-v","errorCode":null,"errorMessage":"failed to create child policy of type %s: %v","messagePattern":"failed to create child policy of type (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/xds/balancer/cdsbalancer/cdsbalancer.go","lineNumber":273,"sourceCode":"\tif err := json.Unmarshal(clusterConfig.Cluster.LBPolicy, &b.xdsLBPolicy); err != nil {\n\t\treturn b.annotateErrorWithNodeID(fmt.Errorf(\"error unmarshalling xDS LB Policy: %v\", err))\n\t}\n\tif err := b.updateChildConfig(); err != nil {\n\t\treturn b.annotateErrorWithNodeID(err)\n\t}\n\treturn nil\n}\n\n// updateChildConfig builds child policy configuration using endpoint addresses\n// returned from the XDSConfig and child policy configuration.\n//\n// A child policy is created if one doesn't already exist. The newly built\n// configuration is then pushed to the child policy.\nfunc (b *cdsBalancer) updateChildConfig() error {\n\tif b.childLB == nil {\n\t\tchildLB, err := newChildBalancer(b.cc, b.bOpts)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create child policy of type %s: %v\", priority.Name, err)\n\t\t}\n\t\tb.childLB = childLB\n\t}\n\n\tchildCfgBytes, endpoints, err := buildPriorityConfigJSON(b.priorities, &b.xdsLBPolicy)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to build child policy config: %v\", err)\n\t}\n\tchildCfg, err := b.childConfigParser.ParseConfig(childCfgBytes)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse child policy config. This should never happen because the config was generated: %v\", err)\n\t}\n\tif b.logger.V(2) {\n\t\tb.logger.Infof(\"Built child policy config: %s\", pretty.ToJSON(childCfg))\n\t}\n\n\tfor i := range endpoints {\n\t\tfor j := range endpoints[i].Addresses {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/xds/balancer/cdsbalancer/cdsbalancer.go#L255-L291","documentation":"Returned by updateChildConfig (line 273) when newChildBalancer(b.cc, b.bOpts) fails. newChildBalancer (lines 46-54) calls balancer.Get(priority.Name) and returns error 341 if nil. So this error wraps error 341 with additional context naming the child policy type. This fires on the first config update when b.childLB is nil and the child priority balancer cannot be constructed.","triggerScenarios":"The first time updateChildConfig runs for a CDS balancer (childLB is nil at line 270), it tries to create the priority child balancer. If the priority builder is not registered, newChildBalancer returns error 341 which is wrapped here as 'failed to create child policy of type priority: ...'.","commonSituations":"Identical to error 341: the priority balancer package is not imported/registered. This is the user-facing wrapper of that root cause, seen during a cluster config update rather than at Build() time.","solutions":["Follow the remediation for error 341: import the full xds package or ensure _ \"google.golang.org/grpc/internal/xds/balancer/priority\" is imported.","Check go.mod for version consistency across grpc-go modules.","Verify no init-order issue is preventing the priority package's init() from running before the CDS balancer is used."],"exampleFix":"// before: missing priority balancer registration\nimport (\n    _ \"google.golang.org/grpc/internal/xds/balancer/cdsbalancer\"\n)\n\n// after: public xds package registers the full balancer chain\nimport (\n    _ \"google.golang.org/grpc/xds\"\n)","handlingStrategy":"validation","validationCode":"// Startup validation: ensure priority balancer is registered\nfunc init() {\n    if balancer.Get(\"priority_experimental\") == nil {\n        log.Fatal(\"priority balancer not registered — import _ \\\"google.golang.org/grpc/xds\\\"\")\n    }\n}","typeGuard":null,"tryCatchPattern":"// Error from UpdateClientConnState propagates to TRANSIENT_FAILURE.\nif strings.Contains(err.Error(), \"failed to create child policy\") {\n    // root cause: unregistered priority balancer; fix imports\n}","preventionTips":["Always import the public xds package in your main package.","Add a startup balancer registration check.","Run 'go mod tidy' to prevent stale or missing dependencies."],"tags":["xds","balancer","child-policy","priority","registration"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}