grpc/grpc-go · error

randomsubsetting: ChildPolicy must be specified

Error message

randomsubsetting: ChildPolicy must be specified

What it means

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.

Solutions

  1. Add a childPolicy entry specifying a registered LB policy (e.g. round_robin, pick_first).
  2. Ensure the child policy name is spelled correctly and is registered in the binary.

Example fix

// before: no childPolicy
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"random_subsetting_experimental":{"subsetSize":10}}]}`)

// after: include a valid childPolicy
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"random_subsetting_experimental":{"subsetSize":10,"childPolicy":[{"round_robin":{}}]}}]}`)
Defensive patterns

Strategy: validation

Validate before calling

// Ensure childPolicy is present.
func validateChildPolicyPresent(childPol any) error {
    if childPol == nil {
        return errors.New("random_subsetting: childPolicy must be specified")
    }
    return nil
}

Prevention

When it happens

Trigger: 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.

Common situations: Operator sets only subsetSize and forgets the required childPolicy; the childPolicy JSON value is null; an xDS control plane omits the child.

Related errors


AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11). Data as JSON: /api/errors/2dc530f60fb7831d. Report an issue: GitHub.

Appendix: source

Thrown at balancer/randomsubsetting/randomsubsetting.go:97

	serviceconfig.LoadBalancingConfig `json:"-"`

	SubsetSize  uint32                         `json:"subsetSize,omitempty"`
	ChildPolicy *iserviceconfig.BalancerConfig `json:"childPolicy,omitempty"`
}

func (bb) ParseConfig(s json.RawMessage) (serviceconfig.LoadBalancingConfig, error) {
	lbCfg := &lbConfig{}

	// Ensure that the specified child policy is registered and validates its
	// config, if present.
	if err := json.Unmarshal(s, lbCfg); err != nil {
		return nil, fmt.Errorf("randomsubsetting: json.Unmarshal failed for configuration: %s with error: %v", string(s), err)
	}
	if lbCfg.SubsetSize == 0 {
		return nil, fmt.Errorf("randomsubsetting: SubsetSize must be greater than 0")
	}
	if lbCfg.ChildPolicy == nil {
		return nil, fmt.Errorf("randomsubsetting: ChildPolicy must be specified")
	}

	return lbCfg, nil
}

func (bb) Name() string {
	return Name
}

type subsettingBalancer struct {
	*gracefulswitch.Balancer

	logger     *internalgrpclog.PrefixLogger
	cfg        *lbConfig
	hashSeed   uint64
	hashDigest *xxhash.Digest
}

View on GitHub (pinned to 0c51461d27)