XTLS/Xray-core · error

Upstream sent malformed statistics.

Error message

Upstream sent malformed statistics.

What it means

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.

Source

Thrown at app/router/command/command.go:125

func (s *routingServer) SubscribeRoutingStats(request *SubscribeRoutingStatsRequest, stream RoutingService_SubscribeRoutingStatsServer) error {
	if s.routingStats == nil {
		return errors.New("Routing statistics not enabled.")
	}
	genMessage := AsProtobufMessage(request.FieldSelectors)
	subscriber, err := stats.SubscribeRunnableChannel(s.routingStats)
	if err != nil {
		return err
	}
	defer stats.UnsubscribeClosableChannel(s.routingStats, subscriber)
	for {
		select {
		case value, ok := <-subscriber:
			if !ok {
				return errors.New("Upstream closed the subscriber channel.")
			}
			route, ok := value.(routing.Route)
			if !ok {
				return errors.New("Upstream sent malformed statistics.")
			}
			err := stream.Send(genMessage(route))
			if err != nil {
				return err
			}
		case <-stream.Context().Done():
			return stream.Context().Err()
		}
	}
}

func (s *routingServer) mustEmbedUnimplementedRoutingServiceServer() {}

type service struct {
	v *core.Instance
}

func (s *service) Register(server *grpc.Server) {

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Ensure only router.Route values are published to the routing stats channel
  2. Clean go.mod/vendor of duplicate or mismatched xray-core versions and rebuild
  3. Report upstream if reproducible on an unmodified build
Defensive patterns

Strategy: type-guard

Type guard

func asRoute(v interface{}) (routing.Route, bool) {
    r, ok := v.(routing.Route)
    return r, ok
}

Prevention

When it happens

Trigger: Something other than routing.Route is published to the routing stats channel (custom publisher, corrupted build, mixed core versions linking different Route types).

Common situations: Forks publishing custom types to the same channel; vendoring two xray-core versions so routing.Route differs per package; extremely unlikely in stock builds.

Understand the failure class

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/57a0ef835a0697cb. Report an issue: GitHub.