spring-cloud / spring-cloud/spring-cloud-gateway

Intermittent wrong filter selection with overlapping route prefixes (equal order) in Spring Cloud Gateway 4.1.6

Open
#3,896 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Im using Spring Cloud Gateway 4.1.6.
Routes are defined in application.properties. Two routes share the same prefix, and I’m not setting the order on the RouteDefinition.

spring.cloud.gateway.routes[0].uri=http://platform-dev.com/
spring.cloud.gateway.routes[0].predicates[0].name=Path
spring.cloud.gateway.routes[0].predicates[0].args[0]=/authentication/token/**
spring.cloud.gateway.routes[0].filters[0]=HeaderFilter
spring.cloud.gateway.routes[0].filters[1]=DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin

spring.cloud.gateway.routes[1].uri=http://platform-dev.com/
spring.cloud.gateway.routes[1].predicates[0].name=Path
spring.cloud.gateway.routes[1].predicates[0].args[0]=/authentication/**
spring.cloud.gateway.routes[1].filters[0]=TokenFilter
spring.cloud.gateway.routes[1].filters[1]=HeaderFilter
spring.cloud.gateway.routes[1].filters[2]=AuthorizationFilter
spring.cloud.gateway.routes[1].filters[3]=DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin

Occasionally after server restarts, requests to endpoints like /authentication/token/getToken get the wrong filters those from the broader route (routes[1]) instead of the more specific route (routes[0]). Its rare and not easily reproducible on demand.

What I observed while debugging:

  • In the PropertiesRouteDefinitionLocator constructor, GatewayProperties shows the routes in the correct order.
  • Later, in CachingRouteLocator.publishRefreshEvent, the signals list is in the wrong order.
  • I know routes are sorted via AnnotationAwareOrderComparator. With equal order values the relative order can be arbitrary, but I dont understand why this leads to the incorrect filters being applied only sometimes.

This looks similar to a past issue that was reported and fixed in older versions:

Im opening this bug because the top-to-bottom order of the application.properties file is not maintained when the order parameter is not present.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with PropertiesRouteDefinitionLocator and CachingRouteLocator.publishRefreshEvent, comparing the route order at construction with the later signals order. Reproduce the restart-dependent behavior using the two application.properties routes and verify that the more specific route consistently receives its intended filters. Done means the route order is deterministic when orders are equal, or the issue's ordering behavior is otherwise clearly resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.