-
Notifications
You must be signed in to change notification settings - Fork 3.4k
CORS configuration is based on outdated RouteDefinitions when using Redis and RefreshRoutesEvent #3774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
Apr 22, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
Apr 22, 2025
…uration-on-redis-refresh
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
Apr 22, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
Apr 22, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
Apr 22, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
May 5, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
May 13, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
May 14, 2025
Configure CORS after refresh routes completed on RefreshRoutesResultEvent Signed-off-by: PeterMue <[email protected]>
PeterMue
added a commit
to PeterMue/spring-cloud-gateway
that referenced
this issue
May 14, 2025
ryanjbaxter
added a commit
that referenced
this issue
May 14, 2025
…redis-refresh Fix CORS configuration timing issue with RedisRouteDefinitionRepository and RefreshRoutesEvent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When using the RedisRouteDefinitionRepository and the actuator endpoint
/gateway/refresh
to refresh the routes, the per-route CORS configuration is done before the actual reload of the routes from the redis completes and thus the CORS configuration is based on the previous state of the route.This happens due to the asynchronous behaviour of the lettuce driver that loads the RouteDefintions from Redis.
The timeline is as follows:
/gateway/refresh
Endpoint emits aRefreshRoutesEvent
org.springframework.cloud.gateway.route.CachingRouteLocator.onApplicationEvent()
is processed(which contains
allRoutes.subscribe(list -> updateCache(Flux.fromIterable(list)), this::handleRefreshError);
)org.springframework.cloud.gateway.filter.cors.CorsGatewayFilterApplicationListener.onApplicationEvent()
isprocessed
Setting some Breakpoints that just log the current Thread reveals exactly this sequence:
As the fetch from redis runs async inside the lettuce EventLoop, there is no guarantee of the correct order of execution.
Versions
Sample
application.properties
/actuator/gateway/routes/cors-sample
GET http://localhost:8080/actuator/gateway/routes/cors-sample
/cors-sample
returns the correct CORS headers/actuator/gateway/refresh
/cors-sample
with the old originAccess-Control-Allow-Origin: *
The text was updated successfully, but these errors were encountered: