-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Caching of ProducesRequestCondition in EndpointHandlerMapping may break custom HandlerMapping or ContentTypeResolver arrangements #20150
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
Hello @ykoyano I can see how we might need to align here with Spring Framework - but the issue you've created only mentions the solution but not the actual problem. Did your application fail because of this problem? What was the problem, what were you trying to do and what was the expected behavior? We need this type of information to properly triage this issue and assign the fix to a milestone. |
Helllo @bclozel, thank you for the reaction. In our team, we provided our own custom Usually, HandlerMapping is executed in the following order.
The value of MediaTypesAttribute cached by However, for some reason, our team executed HandlerMapping in the following order. (I am aware that this is a rare case.)
In this case, the MediaTypesAttribute value cached by the Manipulating the HandlerMapping order can solve the above problem. However, if |
As of spring-projects/spring-framework#22644, Spring Framework caches the "produces" condition when matching for endpoints in the `HandlerMapping` infrastructure. This has been improved in spring-projects/spring-framework#23091 to prevent side-effects in other implementations. Prior to this commit, the Spring Boot actuator infrastructure for `EndpointHandlerMapping` would not clear the cached attribute, presenting the same issue as Spring Framework's infrastructure. This means that a custom arrangement with custom `HandlerMapping` or `ContentTypeResolver` would not work properly and reuse the cached produced conditions for other, unintented, parts of the handler mapping process. This commit clears the cached data and ensures that other handler mapping implementations are free of that side-effect. Fixes gh-20150
Thanks @ykoyano for your contribution - your analysis is spot on and your use case helped triaging this issue! |
Due to the optimization of
ProducesRequestCondition
, HandlerMapping caches MediaTypesAttribute.However,
WebFluxEndpointHandlerMapping
andCloudFoundryWebFluxEndpointHandlerMapping
do not delete the cached MediaTypesAttribute and affect the resolution of MediaTypes of other HandlerMappings. ( On the other hand, the class that inheritsRequestMappingHandlerMapping
deletes the cache.)These issues are occurring not only in Spring Webflux's HandlerMapping but also in Spring MVC's HandlerMapping.
To solve this problem, I think you need one of the following measures:
Add a process to delete the cache at the end of HandlerMapping to
AbstractWebFluxEndpointHandlerMapping
andAbstractWebMvcEndpointHandlerMapping
.Move the process of deleting the cache at the end of HandlerMapping from
RequestMappingHandlerMapping
toRequestMappingInfoHandlerMapping
of the parent class.If my proposed solution is correct, I am ready to create a PR.
Related URL
The text was updated successfully, but these errors were encountered: