{"record":{"id":"57a0ef835a0697cb","repo":"XTLS/Xray-core","slug":"upstream-sent-malformed-statistics","errorCode":null,"errorMessage":"Upstream sent malformed statistics.","messagePattern":"Upstream sent malformed statistics\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/router/command/command.go","lineNumber":125,"sourceCode":"func (s *routingServer) SubscribeRoutingStats(request *SubscribeRoutingStatsRequest, stream RoutingService_SubscribeRoutingStatsServer) error {\n\tif s.routingStats == nil {\n\t\treturn errors.New(\"Routing statistics not enabled.\")\n\t}\n\tgenMessage := AsProtobufMessage(request.FieldSelectors)\n\tsubscriber, err := stats.SubscribeRunnableChannel(s.routingStats)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer stats.UnsubscribeClosableChannel(s.routingStats, subscriber)\n\tfor {\n\t\tselect {\n\t\tcase value, ok := <-subscriber:\n\t\t\tif !ok {\n\t\t\t\treturn errors.New(\"Upstream closed the subscriber channel.\")\n\t\t\t}\n\t\t\troute, ok := value.(routing.Route)\n\t\t\tif !ok {\n\t\t\t\treturn errors.New(\"Upstream sent malformed statistics.\")\n\t\t\t}\n\t\t\terr := stream.Send(genMessage(route))\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\tcase <-stream.Context().Done():\n\t\t\treturn stream.Context().Err()\n\t\t}\n\t}\n}\n\nfunc (s *routingServer) mustEmbedUnimplementedRoutingServiceServer() {}\n\ntype service struct {\n\tv *core.Instance\n}\n\nfunc (s *service) Register(server *grpc.Server) {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/app/router/command/command.go#L107-L143","documentation":"A value received on the routing stats channel failed the routing.Route type assertion. The channel contract expects only Route values, so this indicates an internal invariant break or cross-version mismatch between publisher and subscriber.","triggerScenarios":"Something other than routing.Route is published to the routing stats channel (custom publisher, corrupted build, mixed core versions linking different Route types).","commonSituations":"Forks publishing custom types to the same channel; vendoring two xray-core versions so routing.Route differs per package; extremely unlikely in stock builds.","solutions":["Ensure only router.Route values are published to the routing stats channel","Clean go.mod/vendor of duplicate or mismatched xray-core versions and rebuild","Report upstream if reproducible on an unmodified build"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func asRoute(v interface{}) (routing.Route, bool) {\n    r, ok := v.(routing.Route)\n    return r, ok\n}","tryCatchPattern":null,"preventionTips":["Never publish non-Route values to the routing stats channel","Keep a single xray-core version across the build graph (go mod graph check)","Treat occurrence as a build-integrity incident, not a runtime condition to swallow"],"tags":["routing","stats","type-assertion","internal"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}