Skip to content

When using Tomcat, closing the application context blocks for two seconds for each DispatcherServlet initialised by a request to the mappings endpoint #14898

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

Closed
filiphr opened this issue Oct 18, 2018 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@filiphr
Copy link
Contributor

filiphr commented Oct 18, 2018

Let me try and explain the problem that I am seeing.

With #13186 support for lazy loading DispatcherServlet when hitting /actuator/mappings has been added to Spring Boot 2.0.6. However, when that happens and one tries to close the application it takes 2s per DispatcherServlet to close its WebApplicationContext (this is on 2.0.6.RELEASE). However, if each context was initialized by hitting it's path then everything is fine. Therefore, I think that there might be some problem with the way the async DispatcherServlet(s) are initialized in the Actuator.

I have created a small project that displays the problem. You can find it here.

Note: #13186 actually does not work with 2.1.0.RC1 (which means that you won't see the problem there, as the other contexts are not initialized).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 18, 2018
@wilkinsona wilkinsona self-assigned this Oct 19, 2018
@wilkinsona
Copy link
Member

wilkinsona commented Oct 19, 2018

Thanks for the sample and detailed description of how to reproduce the problem.

It was #9979 that introduced the code that's causing the problem here and application's that use a separate management port will also be affected. It's the Tomcat-specific logic that ensures that the dispatcher servlet has been initialised that's causing the problem. We force initialisation of the dispatcher servlet by asking Tomcat to allocate a Servlet instance from the wrapper. This instance is never deallocated which causes Tomcat to wait for 2000ms during shutdown for each servlet in this state.

@wilkinsona wilkinsona changed the title Closing AnnotationConfigWebApplicationContext of async multi servlet registration is slow Closing AnnotationConfigWebWhen using Tomcat, closing the application context blocks for two seconds for each DispatcherServlet initialised by a request to the mappings endpoint Oct 19, 2018
@wilkinsona wilkinsona changed the title Closing AnnotationConfigWebWhen using Tomcat, closing the application context blocks for two seconds for each DispatcherServlet initialised by a request to the mappings endpoint When using Tomcat, closing the application context blocks for two seconds for each DispatcherServlet initialised by a request to the mappings endpoint Oct 19, 2018
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 19, 2018
@wilkinsona wilkinsona added this to the 2.0.7 milestone Oct 19, 2018
@wilkinsona
Copy link
Member

Note: #13186 actually does not work with 2.1.0.RC1 (which means that you won't see the problem there, as the other contexts are not initialized).

I'm guessing that you're judging this by the log output? With 2.1.0.RC1, your dispatcher servlet is still initialised although the logging is less verbose:

2018-10-19 10:19:46.710  INFO 25285 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'TestServlet service1'
2018-10-19 10:19:46.710  INFO 25285 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'TestServlet service1'
2018-10-19 10:19:46.772  INFO 25285 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 62 ms

And its mappings are included in the output from the mappings endpoint.

If I have misunderstood, can you please open a separate issue (as it's a separate problem) with some more details about the difference in behaviour between 2.0.x and 2.1.

@filiphr
Copy link
Contributor Author

filiphr commented Oct 19, 2018

Thanks for the fast fix of this.

Regarding the #13186.

I'm guessing that you're judging this by the log output? With 2.1.0.RC1, your dispatcher servlet is still initialised although the logging is less verbose:

I had some other issues before when the @EnableWebMvc was not there. It is my mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants