{"record":{"id":"848e2d2add5aad0c","repo":"vitessio/vitess","slug":"failed-to-initialize-service-config-with-load-bala","errorCode":null,"errorMessage":"failed to initialize service config with load balancer policy %s: %s","messagePattern":"failed to initialize service config with load balancer policy (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtadmin/cluster/resolver/resolver.go","lineNumber":265,"sourceCode":"}\n\nfunc (b *builder) build(target grpcresolver.Target, cc grpcresolver.ClientConn, opts grpcresolver.BuildOptions) (*resolver, error) {\n\tvar fn func(context.Context, []string) ([]string, error)\n\tswitch target.URL.Host {\n\tcase \"vtctld\":\n\t\tfn = b.opts.Discovery.DiscoverVtctldAddrs\n\tcase \"vtgate\":\n\t\tfn = b.opts.Discovery.DiscoverVTGateAddrs\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"%s: unsupported URL host %s\", logPrefix, target.URL.Host)\n\t}\n\n\tvar sc serviceconfig.Config\n\tif b.opts.BalancerPolicy != \"\" {\n\t\t// c.f. https://github.com/grpc/grpc/blob/master/doc/service_config.md#example\n\t\tscpr := cc.ParseServiceConfig(fmt.Sprintf(`{\"loadBalancingConfig\": [{ \"%s\": {} }] }`, b.opts.BalancerPolicy))\n\t\tif scpr.Err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to initialize service config with load balancer policy %s: %s\", b.opts.BalancerPolicy, scpr.Err)\n\t\t}\n\n\t\tsc = scpr.Config\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\n\tr := &resolver{\n\t\tcomponent: target.URL.Host,\n\t\t// use the original cluster ID (not the sanitized scheme) for debugging/logging\n\t\tcluster:         b.clusterID,\n\t\tdiscoverAddrs:   fn,\n\t\tbackoffStrategy: backoff.Get(b.opts.BackoffStrategy, b.opts.BackoffConfig),\n\t\topts:            b.opts,\n\t\tcc:              cc,\n\t\tsc:              sc,\n\t\trn:              make(chan struct{}, 1),\n\t\tctx:             ctx,","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtadmin/cluster/resolver/resolver.go#L247-L283","documentation":"During resolver build, if a BalancerPolicy is configured, the builder constructs a gRPC service config JSON ({\"loadBalancingConfig\": [{policy: {}}]}) and asks the ClientConn to parse it. If ParseServiceConfig fails (unknown/unregistered LB policy name or malformed config), this error wraps the parse error with the policy that caused it.","triggerScenarios":"Setting opts.BalancerPolicy to a string that is not a registered gRPC load-balancing policy in this binary (e.g. custom policy never registered via balancer.Register), then calling Build/mustBuild.","commonSituations":"Mismatch between the allowed BalancerPolicy flag values and gRPC's registered balancer names (e.g. registering 'pick_first' in flag but gRPC expects 'pickfirst'); stripped builds where default balancers are not linked in.","solutions":["Confirm the policy string matches the gRPC-registered balancer name ('pickfirst', 'round_robin').","Cross-check with BalancerPolicy.Set validation — use a value accepted there.","Read the wrapped %s (scpr.Err) for gRPC's own explanation.","Remove BalancerPolicy so the default service config is used."],"exampleFix":"// before\nopts.BalancerPolicy = \"pick_first\"\n// after\nopts.BalancerPolicy = \"pickfirst\"","handlingStrategy":"validation","validationCode":"if policy != \"\" {\n  sc := fmt.Sprintf(`{\"loadBalancingConfig\": [{ %q: {} }]}`, policy)\n  if _, err := json.Marshal(json.RawMessage(sc)); err != nil {\n    return fmt.Errorf(\"invalid service config: %w\", err)\n  }\n  bp := resolver.BalancerPolicy(\"\")\n  if err := bp.Set(policy); err != nil {\n    return fmt.Errorf(\"policy %q will fail service config parse\", policy)\n  }\n}","typeGuard":"func isRegisteredGRPCLBPolicy(s string) bool {\n  return balancer.Get(s) != nil\n}","tryCatchPattern":"cc, err := resolver.Build(target, opts)\nif err != nil {\n  if strings.Contains(err.Error(), \"failed to initialize service config\") {\n    opts.BalancerPolicy = \"\"\n    cc, err = resolver.Build(target, opts)\n  }\n  if err != nil { return err }\n}","preventionTips":["Keep BalancerPolicy values consistent with gRPC's registered balancer names.","Test resolver building for every configured policy in CI.","Import _ the balancer packages needed so they register.","Prefer leaving BalancerPolicy empty unless you need a specific balancer."],"tags":["grpc","load-balancing","service-config","resolver"],"backgroundTag":"grpc-service-config-invalid","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}