{"record":{"id":"2dc530f60fb7831d","repo":"grpc/grpc-go","slug":"randomsubsetting-childpolicy-must-be-specified","errorCode":null,"errorMessage":"randomsubsetting: ChildPolicy must be specified","messagePattern":"randomsubsetting: ChildPolicy must be specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"balancer/randomsubsetting/randomsubsetting.go","lineNumber":97,"sourceCode":"\tserviceconfig.LoadBalancingConfig `json:\"-\"`\n\n\tSubsetSize  uint32                         `json:\"subsetSize,omitempty\"`\n\tChildPolicy *iserviceconfig.BalancerConfig `json:\"childPolicy,omitempty\"`\n}\n\nfunc (bb) ParseConfig(s json.RawMessage) (serviceconfig.LoadBalancingConfig, error) {\n\tlbCfg := &lbConfig{}\n\n\t// Ensure that the specified child policy is registered and validates its\n\t// config, if present.\n\tif err := json.Unmarshal(s, lbCfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"randomsubsetting: json.Unmarshal failed for configuration: %s with error: %v\", string(s), err)\n\t}\n\tif lbCfg.SubsetSize == 0 {\n\t\treturn nil, fmt.Errorf(\"randomsubsetting: SubsetSize must be greater than 0\")\n\t}\n\tif lbCfg.ChildPolicy == nil {\n\t\treturn nil, fmt.Errorf(\"randomsubsetting: ChildPolicy must be specified\")\n\t}\n\n\treturn lbCfg, nil\n}\n\nfunc (bb) Name() string {\n\treturn Name\n}\n\ntype subsettingBalancer struct {\n\t*gracefulswitch.Balancer\n\n\tlogger     *internalgrpclog.PrefixLogger\n\tcfg        *lbConfig\n\thashSeed   uint64\n\thashDigest *xxhash.Digest\n}\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/balancer/randomsubsetting/randomsubsetting.go#L79-L115","documentation":"Returned by random_subsetting_experimental's ParseConfig() (balancer/randomsubsetting/randomsubsetting.go:97). The ChildPolicy field is a pointer (*iserviceconfig.BalancerConfig) that is nil when not present in the JSON. random_subsetting requires a child policy to delegate the actual load balancing of the selected subset, so a nil child policy is rejected.","triggerScenarios":"The random_subsetting_experimental config has no childPolicy field (or it is null). ParseConfig() reaches line 96 with lbCfg.ChildPolicy == nil and returns the error.","commonSituations":"Operator sets only subsetSize and forgets the required childPolicy; the childPolicy JSON value is null; an xDS control plane omits the child.","solutions":["Add a childPolicy entry specifying a registered LB policy (e.g. round_robin, pick_first).","Ensure the child policy name is spelled correctly and is registered in the binary."],"exampleFix":"// before: no childPolicy\ngrpc.WithDefaultServiceConfig(`{\"loadBalancingConfig\":[{\"random_subsetting_experimental\":{\"subsetSize\":10}}]}`)\n\n// after: include a valid childPolicy\ngrpc.WithDefaultServiceConfig(`{\"loadBalancingConfig\":[{\"random_subsetting_experimental\":{\"subsetSize\":10,\"childPolicy\":[{\"round_robin\":{}}]}}]}`)","handlingStrategy":"validation","validationCode":"// Ensure childPolicy is present.\nfunc validateChildPolicyPresent(childPol any) error {\n    if childPol == nil {\n        return errors.New(\"random_subsetting: childPolicy must be specified\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include childPolicy in random_subsetting configs.","Validate the config struct is fully populated before serializing to JSON."],"tags":["grpc","balancer","random-subsetting","config","validation","child-policy"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}