grpc/grpc-go · error

randomsubsetting: json.Unmarshal failed for configuration

Error message

randomsubsetting: json.Unmarshal failed for configuration: %s with error: %v

What it means

Returned by random_subsetting_experimental's ParseConfig() (balancer/randomsubsetting/randomsubsetting.go:91) when json.Unmarshal of the raw config into lbConfig fails. lbConfig has SubsetSize (uint32) and ChildPolicy fields. The %s shows the raw JSON, %v the unmarshal error. This blocks the channel from applying the policy.

Solutions

  1. Validate the JSON with a linter.
  2. Use the exact field names: subsetSize (uint32) and childPolicy (object).
  3. Read the %s and %v to find the offending token.
  4. Confirm the config came from a correct source (xDS resource or service config).

Example fix

// before: subsetSize as a string and wrong field name
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"random_subsetting_experimental":{"subsetSize":"10","childPolicy":{"round_robin":{}}}}]}`)

// after: subsetSize as a number with correct camelCase field names
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"random_subsetting_experimental":{"subsetSize":10,"childPolicy":[{"round_robin":{}}]}}]}`)
Defensive patterns

Strategy: validation

Validate before calling

// Validate random_subsetting config JSON before applying.
func validateRandomSubsettingConfig(js string) error {
    var cfg struct {
        SubsetSize  uint32 `json:"subsetSize,omitempty"`
        ChildPolicy *json.RawMessage `json:"childPolicy,omitempty"`
    }
    return json.Unmarshal([]byte(js), &cfg)
}

Prevention

When it happens

Trigger: The random_subsetting_experimental config entry is malformed JSON or has wrong field types (e.g. subsetSize as a string). ParseConfig() is invoked during service config parsing and json.Unmarshal returns a non-nil error at line 90.

Common situations: Hand-written service config with a JSON syntax error; subsetSize given as a string; an xDS control plane sends a malformed config; a field name typo like 'subset_size' instead of 'subsetSize'.

Related errors


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

Appendix: source

Thrown at balancer/randomsubsetting/randomsubsetting.go:91

	b.logger = prefixLogger(b)
	b.logger.Infof("Created")
	return b
}

type lbConfig struct {
	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

View on GitHub (pinned to 0c51461d27)