Ensure embedded containers actually stop if there is an error on startup
Both embedded containers need to be checked after starting to ensure that they are actually running. With Jetty it's just a question of catching an exception but with Tomcat it's harder (the current solution involves duplicating some code from initialize() into start() essentially checking the lifecycle state). Also adjusted the log levels to prevent noise at WARN level by default when this happens (since the exception is logged and rethrown anyway). There is still the issue of whether to fail the build in Maven or Gradle (separate issue really). Fixes gh-1232
This commit is contained in:
parent
ede385d1b6
commit
81a4548561
|
@ -75,6 +75,12 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
|
|||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
try {
|
||||
// Ensure process isn't left running
|
||||
this.server.stop();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
throw new EmbeddedServletContainerException(
|
||||
"Unable to start embedded Jetty servlet container", ex);
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|||
this.tomcat.stop();
|
||||
throw new IllegalStateException("Tomcat connector in failed state");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new EmbeddedServletContainerException(
|
||||
|
@ -151,6 +152,15 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|||
if (connector != null && this.autoStart) {
|
||||
startConnector(connector);
|
||||
}
|
||||
// Ensure process isn't left running if it actually failed to start
|
||||
if (LifecycleState.FAILED.equals(this.tomcat.getConnector().getState())) {
|
||||
try {
|
||||
this.tomcat.stop();
|
||||
}
|
||||
catch (LifecycleException e) {
|
||||
}
|
||||
throw new IllegalStateException("Tomcat connector in failed state");
|
||||
}
|
||||
}
|
||||
|
||||
private void addPreviouslyRemovedConnectors() {
|
||||
|
@ -213,11 +223,11 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|||
try {
|
||||
try {
|
||||
this.tomcat.stop();
|
||||
this.tomcat.destroy();
|
||||
}
|
||||
catch (LifecycleException ex) {
|
||||
// swallow and continue
|
||||
}
|
||||
this.tomcat.destroy();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new EmbeddedServletContainerException("Unable to stop embedded Tomcat",
|
||||
|
|
|
@ -88,6 +88,7 @@ public class LoggingApplicationListener implements SmartApplicationListener {
|
|||
LOG_LEVEL_LOGGERS.add(LogLevel.DEBUG, "org.springframework.boot");
|
||||
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.springframework");
|
||||
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.apache.tomcat");
|
||||
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.apache.catalina");
|
||||
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.eclipse.jetty");
|
||||
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.hibernate.tool.hbm2ddl");
|
||||
}
|
||||
|
|
|
@ -9,3 +9,5 @@ org.apache.coyote.http11.Http11NioProtocol.level = WARNING
|
|||
org.crsh.plugin.level = WARNING
|
||||
org.apache.tomcat.util.net.NioSelectorPool.level = WARNING
|
||||
org.apache.catalina.startup.DigesterFactory.level = SEVERE
|
||||
org.apache.catalina.util.LifecycleBase.level = SEVERE
|
||||
org.eclipse.jetty.util.component.AbstractLifeCycle.level = SEVERE
|
||||
|
|
|
@ -16,3 +16,5 @@ org.apache.coyote.http11.Http11NioProtocol.level = WARNING
|
|||
org.crsh.plugin.level = WARNING
|
||||
org.apache.tomcat.util.net.NioSelectorPool.level = WARNING
|
||||
org.apache.catalina.startup.DigesterFactory.level = SEVERE
|
||||
org.apache.catalina.util.LifecycleBase.level = SEVERE
|
||||
org.eclipse.jetty.util.component.AbstractLifeCycle.level = SEVERE
|
||||
|
|
|
@ -13,3 +13,5 @@ log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN
|
|||
log4j.category.org.crsh.plugin=WARN
|
||||
log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN
|
||||
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR
|
||||
log4j.category.org.apache.catalina.util.LifecycleBase=ERROR
|
||||
log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR
|
||||
|
|
|
@ -21,3 +21,5 @@ log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN
|
|||
log4j.category.org.crsh.plugin=WARN
|
||||
log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN
|
||||
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR
|
||||
log4j.category.org.apache.catalina.util.LifecycleBase=ERROR
|
||||
log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
<logger name="org.crsh.plugin" level="WARN"/>
|
||||
<logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN"/>
|
||||
<logger name="org.apache.catalina.startup.DigesterFactory" level="ERROR"/>
|
||||
<logger name="org.apache.catalina.util.LifecycleBase" level="ERROR"/>
|
||||
<logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="ERROR"/>
|
||||
<logger name="org.thymeleaf" additivity="false">
|
||||
<appender-ref ref="DEBUG_LEVEL_REMAPPER"/>
|
||||
</logger>
|
||||
|
|
Loading…
Reference in New Issue