{"record":{"id":"36109e2284ebcb3e","repo":"grpc/grpc-go","slug":"multiple-orca-load-reports-found-in-provided-metad","errorCode":null,"errorMessage":"multiple orca load reports found in provided metadata","messagePattern":"multiple orca load reports found in provided metadata","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"orca/internal/internal.go","lineNumber":64,"sourceCode":"// transmitted.\nconst TrailerMetadataKey = \"endpoint-load-metrics-bin\"\n\n// ToLoadReport unmarshals a binary encoded [ORCA LoadReport] protobuf message\n// from md and returns the corresponding struct. The load report is expected to\n// be stored as the value for key \"endpoint-load-metrics-bin\".\n//\n// If no load report was found in the provided metadata, if multiple load\n// reports are found, or if the load report found cannot be parsed, an error is\n// returned.\n//\n// [ORCA LoadReport]: (https://github.com/cncf/xds/blob/main/xds/data/orca/v3/orca_load_report.proto#L15)\nfunc ToLoadReport(md metadata.MD) (*v3orcapb.OrcaLoadReport, error) {\n\tvs := md.Get(TrailerMetadataKey)\n\tif len(vs) == 0 {\n\t\treturn nil, nil\n\t}\n\tif len(vs) != 1 {\n\t\treturn nil, errors.New(\"multiple orca load reports found in provided metadata\")\n\t}\n\tret := new(v3orcapb.OrcaLoadReport)\n\tif err := proto.Unmarshal([]byte(vs[0]), ret); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal load report found in metadata: %v\", err)\n\t}\n\treturn ret, nil\n}\n","sourceCodeStart":46,"sourceCodeEnd":72,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/orca/internal/internal.go#L46-L72","documentation":"Returned by ToLoadReport when the gRPC trailer/response metadata contains more than one value for the ORCA load-report key \"endpoint-load-metrics-bin\". The ORCA protocol expects at most one binary-encoded OrcaLoadReport per call; multiple values indicate a malformed/interleaved report and the function refuses to guess which one to use.","triggerScenarios":"Calling orca/internal.ToLoadReport(md) on a metadata.MD where md.Get(\"endpoint-load-metrics-bin\") returns a slice of length > 1. Can happen if a server/interceptor appends the trailer twice, or if metadata from multiple backends is merged incorrectly.","commonSituations":"A custom balancer/interceptor copies ORCA trailers across hop boundaries and double-appends. Aggregating metadata from several sub-streams into one metadata.MD without de-duplication. A buggy server adds the trailer both in headers and trailers.","solutions":["Find the component that appends \"endpoint-load-metrics-bin\" twice and ensure it is added exactly once per RPC.","De-duplicate the metadata before calling ToLoadReport (keep the first/last bytewise value).","If you intentionally merged metadata from multiple backends, split the reports and parse each separately.","Update the offending interceptor/balancer to use metadata.Append only when the key is absent."],"exampleFix":"// before\nfunc handle(md metadata.MD) {\n    rpt, _ := orcainternal.ToLoadReport(md) // md has 2 values for endpoint-load-metrics-bin\n}\n// after: ensure single append on the producer side, or de-dup on the consumer side\nfunc handle(md metadata.MD) {\n    vs := md.Get(orcainternal.TrailerMetadataKey)\n    if len(vs) > 1 { md.Set(orcainternal.TrailerMetadataKey, vs[len(vs)-1]) }\n    rpt, _ := orcainternal.ToLoadReport(md)\n}","handlingStrategy":"try-catch","validationCode":"// De-duplicate ORCA trailer values before parsing.\nfunc sanitizeORCAMetadata(md metadata.MD) metadata.MD {\n    vs := md.Get(orcainternal.TrailerMetadataKey)\n    if len(vs) > 1 {\n        md.Set(orcainternal.TrailerMetadataKey, vs[len(vs)-1]) // keep the last report\n    }\n    return md\n}","typeGuard":null,"tryCatchPattern":"if _, err := orcainternal.ToLoadReport(md); err != nil { if strings.Contains(err.Error(), \"multiple orca load reports\") { md = sanitizeORCAMetadata(md); rpt, err = orcainternal.ToLoadReport(md) }; if err != nil { /* record metric, continue without ORCA data */ } }","preventionTips":["Never call metadata.Append for the ORCA trailer more than once per RPC.","When merging metadata across hops, dedup binary-valued keys before forwarding.","In test harnesses, assert exactly one endpoint-load-metrics-bin value per call."],"tags":["orca","load-reporting","metadata","grpc-trailer"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}