{"record":{"id":"89dcb33e87721437","repo":"grpc/grpc-go","slug":"unexpected-balancer-config-with-type-t-89dcb3","errorCode":null,"errorMessage":"unexpected balancer config with type: %T","messagePattern":"unexpected balancer config with type: %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/xds/balancer/clusterimpl/clusterimpl.go","lineNumber":404,"sourceCode":"\toldHI := b.xdsHIPtr.Swap(newHI)\n\tif oldHI != nil {\n\t\toldHI.Decrement()\n\t}\n\treturn nil\n}\n\nfunc (b *clusterImplBalancer) UpdateClientConnState(s balancer.ClientConnState) error {\n\tdefer clientConnUpdateHook()\n\n\tb.mu.Lock()\n\tb.inhibitPickerUpdates = true\n\tb.mu.Unlock()\n\tif b.logger.V(2) {\n\t\tb.logger.Infof(\"Received configuration: %s\", pretty.ToJSON(s.BalancerConfig))\n\t}\n\tnewConfig, ok := s.BalancerConfig.(*LBConfig)\n\tif !ok {\n\t\treturn fmt.Errorf(\"unexpected balancer config with type: %T\", s.BalancerConfig)\n\t}\n\n\t// Need to check for potential errors at the beginning of this function, so\n\t// that on errors, we reject the whole config, instead of applying part of\n\t// it.\n\tbb := balancer.Get(newConfig.ChildPolicy.Name)\n\tif bb == nil {\n\t\treturn fmt.Errorf(\"child policy %q not registered\", newConfig.ChildPolicy.Name)\n\t}\n\n\tif b.xdsClient == nil {\n\t\tc := xdsclient.FromResolverState(s.ResolverState)\n\t\tif c == nil {\n\t\t\treturn balancer.ErrBadResolverState\n\t\t}\n\t\tb.xdsClient = c\n\t}\n","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/xds/balancer/clusterimpl/clusterimpl.go#L386-L422","documentation":"Returned by xds_cluster_impl's UpdateClientConnState when s.BalancerConfig cannot be type-asserted to *clusterimpl.LBConfig (clusterimpl.go:402-404). The cluster_impl policy only accepts its own strongly-typed config carrying the cluster name, drop categories, security cfg, and child policy. Any other type means the upstream resolver/balancer produced the wrong shape and the whole update is rejected.","triggerScenarios":"UpdateClientConnState is invoked on a cluster_impl balancer with s.BalancerConfig of any type other than *clusterimpl.LBConfig (e.g. *clustermanager.lbConfig, *priority.LBConfig, a raw struct, or nil where the assertion expects non-nil).","commonSituations":"A custom parent balancer that bypasses clusterimpl.ParseConfig and hands down a different struct; gRPC-go version drift where the LBConfig struct layout changed between the resolver and the balancer plugin; tests that construct ClientConnState manually with the wrong config type.","solutions":["Route the config through clusterimpl.ParseConfig(rawJSON) and pass the returned *LBConfig as BalancerConfig.","If writing a custom parent balancer, never wrap or translate the config into a different type before calling UpdateClientConnState.","Verify resolver and balancer plugin come from the same gRPC-go version."],"exampleFix":"// before\nb.UpdateClientConnState(balancer.ClientConnState{\n    BalancerConfig: &SomeOtherConfig{}, // wrong type\n})\n// after\nimport \"google.golang.org/grpc/internal/xds/balancer/clusterimpl\"\ncfg, err := clusterimpl.ParseConfig(rawJSON)\nif err != nil { return err }\nb.UpdateClientConnState(balancer.ClientConnState{\n    BalancerConfig: cfg, // *clusterimpl.LBConfig\n})","handlingStrategy":"type-guard","validationCode":"// Before invoking UpdateClientConnState, ensure the config is *clusterimpl.LBConfig.\nfunc validateClusterImplConfig(cfg serviceconfig.LoadBalancingConfig) error {\n    if _, ok := cfg.(*clusterimpl.LBConfig); !ok {\n        return fmt.Errorf(\"expected *clusterimpl.LBConfig, got %T\", cfg)\n    }\n    return nil\n}","typeGuard":"func isClusterImplConfig(cfg serviceconfig.LoadBalancingConfig) bool {\n    _, ok := cfg.(*clusterimpl.LBConfig)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Always produce the config via clusterimpl.ParseConfig rather than constructing it manually.","Do not wrap or translate the LBConfig into a different type between resolver and balancer.","Pin resolver and balancer packages to the same gRPC-go version."],"tags":["go","grpc","xds","balancer","config-type","clusterimpl"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}