{"record":{"id":"417ec260b4a98685","repo":"grpc/grpc-go","slug":"failed-to-marshal-built-priority-config-struct-int","errorCode":null,"errorMessage":"failed to marshal built priority config struct into json: %v","messagePattern":"failed to marshal built priority config struct into json: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/xds/balancer/cdsbalancer/configbuilder.go","lineNumber":103,"sourceCode":"//\t          ┌────────┐\n//\t          │priority│\n//\t          └┬──────┬┘\n//\t           │      │\n//\t┌──────────▼─┐  ┌─▼──────────┐\n//\t│cluster_impl│  │cluster_impl│\n//\t└──────┬─────┘  └─────┬──────┘\n//\t       │              │\n//\t┌──────▼─────┐  ┌─────▼──────┐\n//\t│xDSLBPolicy │  │xDSLBPolicy │ (Locality and Endpoint picking layer)\n//\t└────────────┘  └────────────┘\nfunc buildPriorityConfigJSON(priorities []*priorityConfig, xdsLBPolicy *internalserviceconfig.BalancerConfig) ([]byte, []resolver.Endpoint, error) {\n\tpc, endpoints, err := buildPriorityConfig(priorities, xdsLBPolicy)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to build priority config: %v\", err)\n\t}\n\tret, err := json.Marshal(pc)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to marshal built priority config struct into json: %v\", err)\n\t}\n\treturn ret, endpoints, nil\n}\n\nfunc buildPriorityConfig(priorities []*priorityConfig, xdsLBPolicy *internalserviceconfig.BalancerConfig) (*priority.LBConfig, []resolver.Endpoint, error) {\n\tvar (\n\t\tretConfig    = &priority.LBConfig{Children: make(map[string]*priority.Child)}\n\t\tretEndpoints []resolver.Endpoint\n\t)\n\tfor _, p := range priorities {\n\t\tclusterUpdate := p.clusterConfig.Cluster\n\t\tswitch clusterUpdate.ClusterType {\n\t\tcase xdsresource.ClusterTypeEDS:\n\t\t\tnames, configs, endpoints, err := buildClusterImplConfigForEDS(p.childNameGen, p.clusterConfig, xdsLBPolicy)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, err\n\t\t\t}\n\t\t\tretConfig.Priorities = append(retConfig.Priorities, names...)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/internal/xds/balancer/cdsbalancer/configbuilder.go#L85-L121","documentation":"After successfully building the priority config Go struct, the CDS balancer marshals it to JSON to pass to the child policy's parser. This error fires when json.Marshal fails on the internally constructed struct. Since the struct is built by gRPC's own code from already-validated data, this error indicates either a programming bug or an impossible state.","triggerScenarios":"Triggered in configbuilder.go when json.Marshal(pc) returns an error after buildPriorityConfig succeeded. The struct is a priority.LBConfig containing internally-constructed cluster_impl and outlier detection configs. json.Marshal can fail on unsupported types, cyclic references, or nil map values with custom marshalers.","commonSituations":"This should essentially never happen in production — it indicates an internal gRPC bug where the config struct contains a value that cannot be marshaled. Could theoretically occur with an unsupported custom type in a custom build, or a regression in a grpc-go version.","solutions":["This is an internal gRPC error — report it as a bug with the grpc-go version and cluster configuration details","Try upgrading to the latest grpc-go patch release to see if the bug has been fixed","Enable GRPC_GO_LOG_SEVERITY=info and capture the full error detail to include in the bug report","As a temporary workaround, simplify the cluster configuration (e.g., remove outlier detection or aggregate clusters) to isolate which config triggers the marshal failure"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// No pre-validation possible — this is an internal struct-to-JSON marshal failure\n// Indicates a gRPC bug; not preventable by user code","typeGuard":null,"tryCatchPattern":"// Report as a bug; monitor for persistence\nif conn.GetState() == connectivity.TransientFailure {\n    // collect full error details and grpc-go version for bug report\n}","preventionTips":["Keep grpc-go updated to the latest stable release","Report internal marshal failures with full logs and cluster config details","Test grpc-go upgrades in staging before production","Simplify cluster configurations to isolate which feature triggers the bug"],"tags":["xds","cds","json","config-builder","internal-bug"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}