XTLS/Xray-core · error

Invalid routing request.

Error message

Invalid routing request.

What it means

TestRoute immediately rejects requests whose RoutingContext field is nil, since there is nothing to route. It is pure request validation occurring before PickRoute is invoked.

Source

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

				RuleTag: v.GetRuleTag(),
			})
		}
		return response, nil
	}
	return nil, errors.New("unsupported router implementation")
}

// NewRoutingServer creates a statistics service with statistics manager.
func NewRoutingServer(router routing.Router, routingStats stats.Channel) RoutingServiceServer {
	return &routingServer{
		router:       router,
		routingStats: routingStats,
	}
}

func (s *routingServer) TestRoute(ctx context.Context, request *TestRouteRequest) (*RoutingContext, error) {
	if request.RoutingContext == nil {
		return nil, errors.New("Invalid routing request.")
	}
	route, err := s.router.PickRoute(AsRoutingContext(request.RoutingContext))
	if err != nil {
		return nil, err
	}
	if request.PublishResult && s.routingStats != nil {
		ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
		s.routingStats.Publish(ctx, route)
	}
	return AsProtobufMessage(request.FieldSelectors)(route), nil
}

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)

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Populate request.RoutingContext with at least the required fields (target/network) before calling TestRoute
  2. Add a nil check client-side to return a clearer local error
  3. Validate the protobuf marshaling/unmarshaling path if the field should have been set

Example fix

// before
req := &command.TestRouteRequest{PublishResult: true}
resp, err := client.TestRoute(ctx, req) // Invalid routing request.

// after
req := &command.TestRouteRequest{
    RoutingContext: &router.RoutingContext{
        Target: &net.IPOrDomain{Domain: "example.com"},
        Network: net.Network_TCP,
    },
}
Defensive patterns

Strategy: validation

Validate before calling

if req.RoutingContext == nil {
    return fmt.Errorf("RoutingContext is required for TestRoute")
}

Prevention

When it happens

Trigger: Sending TestRouteRequest with RoutingContext unset (default nil in protobuf), e.g. building the request struct without populating the field.

Common situations: Client code constructing TestRouteRequest{} and forgetting the nested message; decoding failures silently yielding nil; schema changes where the field was renamed.

Related errors


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