{"record":{"id":"5c0a1dadf50b3259","repo":"grpc/grpc-go","slug":"xds-wrr-locality-error-marshalling-prepared-confi","errorCode":null,"errorMessage":"xds_wrr_locality: error marshalling prepared config: %v","messagePattern":"xds_wrr_locality: error marshalling prepared config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/xds/balancer/wrrlocality/balancer.go","lineNumber":178,"sourceCode":"\n\tweightedTargets := make(map[string]weightedtarget.Target)\n\tfor _, ep := range s.ResolverState.Endpoints {\n\t\t// This get of LocalityID could potentially return a zero value. This\n\t\t// shouldn't happen though (this attribute that is set actually gets\n\t\t// used to build localities in the first place), and thus don't error\n\t\t// out, and just build a weighted target with undefined behavior.\n\t\tlocality := xdsinternal.LocalityString(xdsinternal.LocalityIDFromEndpoint(ep))\n\t\tai, ok := getAddrInfo(ep)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"xds_wrr_locality: missing locality weight information in endpoint %q\", ep)\n\t\t}\n\t\tweightedTargets[locality] = weightedtarget.Target{Weight: ai.LocalityWeight, ChildPolicy: lbCfg.ChildPolicy}\n\t}\n\twtCfg := &weightedtarget.LBConfig{Targets: weightedTargets}\n\twtCfgJSON, err := json.Marshal(wtCfg)\n\tif err != nil {\n\t\t// Shouldn't happen.\n\t\treturn fmt.Errorf(\"xds_wrr_locality: error marshalling prepared config: %v\", wtCfg)\n\t}\n\tvar sc serviceconfig.LoadBalancingConfig\n\tif sc, err = b.childParser.ParseConfig(wtCfgJSON); err != nil {\n\t\treturn fmt.Errorf(\"xds_wrr_locality: config generated %v is invalid: %v\", wtCfgJSON, err)\n\t}\n\n\treturn b.child.UpdateClientConnState(balancer.ClientConnState{\n\t\tResolverState:  s.ResolverState,\n\t\tBalancerConfig: sc,\n\t})\n}\n\nfunc (b *wrrLocalityBalancer) ResolverError(err error) {\n\tb.child.ResolverError(err)\n}\n\nfunc (b *wrrLocalityBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {\n\tb.logger.Errorf(\"UpdateSubConnState(%v, %+v) called unexpectedly\", sc, state)","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/xds/balancer/wrrlocality/balancer.go#L160-L196","documentation":"Returned when json.Marshal of the internally-built weightedtarget.LBConfig fails inside UpdateClientConnState. The source comment marks this 'Shouldn't happen' because the struct is composed of plain maps and uint32 weights that are always marshalable. It is a defensive guard against an unreachable condition.","triggerScenarios":"Reached at balancer.go:178 only if json.Marshal(wtCfg) errors. With weightedtarget.LBConfig containing map[string]Target and uint32 weights, standard encoding/json cannot fail in normal operation.","commonSituations":"Effectively unreachable. Could surface only under memory corruption, a nil map oddity in a patched/forked gRPC, or a future struct change introducing a non-marshalable field.","solutions":["Treat occurrence as a gRPC bug: capture the wtCfg value (printed in the error) and file an issue with the grpc-go maintainers.","Verify you are running an unmodified grpc-go release (no local patches to weightedtarget.LBConfig).","Upgrade to the latest grpc-go patch release in case it was a transient regression."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Treat as an unrecoverable internal error; do not retry identical input.\nif err := b.UpdateClientConnState(s); err != nil && strings.Contains(err.Error(), \"error marshalling prepared config\") {\n    // Capture the printed wtCfg and report upstream; fall back to a different LB policy.\n}","preventionTips":["Run an unmodified grpc-go release.","If this fires, capture the wtCfg value from the error and file a grpc-go bug.","Keep dependencies locked to known-good grpc-go versions."],"tags":["grpc","xds","balancer","wrr-locality","internal","go"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}