{"record":{"id":"b2fc36b383af836f","repo":"grpc/grpc-go","slug":"randomsubsetting-json-unmarshal-failed-for-config","errorCode":null,"errorMessage":"randomsubsetting: json.Unmarshal failed for configuration: %s with error: %v","messagePattern":"randomsubsetting: json\\.Unmarshal failed for configuration: (.+?) with error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"balancer/randomsubsetting/randomsubsetting.go","lineNumber":91,"sourceCode":"\tb.logger = prefixLogger(b)\n\tb.logger.Infof(\"Created\")\n\treturn b\n}\n\ntype lbConfig struct {\n\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","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/balancer/randomsubsetting/randomsubsetting.go#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","solutions":["Validate the JSON with a linter.","Use the exact field names: subsetSize (uint32) and childPolicy (object).","Read the %s and %v to find the offending token.","Confirm the config came from a correct source (xDS resource or service config)."],"exampleFix":"// before: subsetSize as a string and wrong field name\ngrpc.WithDefaultServiceConfig(`{\"loadBalancingConfig\":[{\"random_subsetting_experimental\":{\"subsetSize\":\"10\",\"childPolicy\":{\"round_robin\":{}}}}]}`)\n\n// after: subsetSize as a number with correct camelCase field names\ngrpc.WithDefaultServiceConfig(`{\"loadBalancingConfig\":[{\"random_subsetting_experimental\":{\"subsetSize\":10,\"childPolicy\":[{\"round_robin\":{}}]}}]}`)","handlingStrategy":"validation","validationCode":"// Validate random_subsetting config JSON before applying.\nfunc validateRandomSubsettingConfig(js string) error {\n    var cfg struct {\n        SubsetSize  uint32 `json:\"subsetSize,omitempty\"`\n        ChildPolicy *json.RawMessage `json:\"childPolicy,omitempty\"`\n    }\n    return json.Unmarshal([]byte(js), &cfg)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exact camelCase field names (subsetSize, childPolicy).","Lint service config JSON in CI.","Test ParseConfig with sample configs."],"tags":["grpc","balancer","random-subsetting","config","json","validation"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}