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

Embedded Tomcat (9.0.14 and above) is not completely shutdown / stucks when there was a (Bean-)Exception during its initialization #17139

Closed
stefanocke opened this issue Jun 13, 2019 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@stefanocke
Copy link

stefanocke commented Jun 13, 2019

Spring Boot version: 2.1.2 and above (Tomcat 9.0.14 and above)

Steps to reproduce:

  • Create a Spring Starter Project with Web MVC and Actuators
  • Create the following Health-Endpoint:
@Component
public class ExampleHealthIndicator implements InitializingBean, HealthIndicator {

    public void afterPropertiesSet() throws Exception {
        throw new RuntimeException("Foo");
    }


    public Health health() {
        return Health.up().build();
    }

}

Expected Behavior:

  • There should be some exception messages and the Spring Boot application should shutdown.

Actual Behavior:

  • The Spring Boot Application does not shutdown. There are 2 remaining non-deamon threads "Catalina-utility-"

Possible Explanation:

AFAIU, there have been the following changes regarding those Catalina-Utility-threads:

  • They have been made non-deamon. (See org.apache.catalina.core.StandardServer.reconfigureUtilityExecutor(int))
  • Their threadpool is only shutdown, when Tomcat / Catalina is destroyed (see org.apache.catalina.core.StandardServer.destroyInternal())

In Spring Boot, the following happens:

  • Tomcat is started in org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize()
  • The exception occures and is catched.
  • stopSilently() is called, which stops Tomcat / Catalina but does not destroy it.
  • Tomcat is never destroyed, since in org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.stopAndReleaseWebServer(), this.webServer is null
  • since Tomcat is never destroyed, the non-deamon thread pool for Catalina-Utility-threads is not shutdown
  • the Spring Boot App never terminates

I cannot tell whether this is wrong behavior in Tomcat or whether Spring Boot has to take care about calling destroy in error case.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 13, 2019
@wilkinsona
Copy link
Member

Thanks for the analysis. This is a duplicate of #16892. The problem should be fixed in the latest 2.1.6 and 2.2.0 snapshots.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 13, 2019
@stefanocke
Copy link
Author

@wilkinsona , thank you. Great to hear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants