Skip to content
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

ResourceUrlProvider detects wrong set of handler mappings #26561

Closed
bclozel opened this issue Feb 17, 2021 · 0 comments
Closed

ResourceUrlProvider detects wrong set of handler mappings #26561

bclozel opened this issue Feb 17, 2021 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Feb 17, 2021

See spring-projects/spring-boot#25113 for more context.

ResourceUrlProvider is listening on ContextRefreshedEvent to detect automatically instances of SimpleUrlHandlerMapping and use them for writing URLs to resources. Once handlers are detected the provider locks itself from further modifications.

With a parent/child context setup and under specific conditions due to ordering, the ResourceUrlProvider might receive a ContextRefreshedEvent from a child context first, thus detecting the wrong set of handlers and ignoring the expected ContextRefreshedEvent once all components are ready in the current context.

We must ensure that ResourceUrlProvider only considers events sent by the current context - this is a common pattern in other parts of Spring Framework.

@bclozel bclozel added the type: bug A general bug label Feb 17, 2021
@bclozel bclozel added this to the 5.3.5 milestone Feb 17, 2021
@bclozel bclozel self-assigned this Feb 17, 2021
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x labels Feb 17, 2021
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 22, 2021
This was referenced Mar 16, 2021
This was referenced Mar 17, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Prior to this commit, `ResourceUrlProvider` would listen and consider
all `ContextRefreshedEvent` and use the given context to detect
`SimpleUrlHandlerMapping`.

This could lead to situations where a `ResourceUrlProvider` uses another
application context than its own (in a parent/child context setup) and
detect the wrong set of handlers.

Because `ResourceUrlProvider` locks itself once the auto-detection is
done, we need to ensure that it considers only events sent by its
application context.

Fixes spring-projectsgh-26561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants