As reported originally on https://github.com/sdeleuze/spring-boot-crac-demo/issues/3, restoration with spring-boot-starter-actuator is fine with the default configuration but fails with a custom management port.
To reproduce:
- Clone https://github.com/sdeleuze/spring-boot-crac-demo
- Add management.server.port=8888 to src/main/resources/application.properties
- Run ./checkpoint.sh then ./restore.sh
Comment From: wilkinsona
This can be reproduced with spring-boot-smoke-test-actuator by stopping and starting the context:
public static void main(String[] args) {
SpringApplication application = new SpringApplication(SampleActuatorApplication.class);
application.setApplicationStartup(new BufferingApplicationStartup(1024));
ConfigurableApplicationContext context = application.run(args);
context.stop();
context.start();
}
Resulting failure:
Exception in thread "main" org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:287)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:467)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:256)
at org.springframework.context.support.DefaultLifecycleProcessor.start(DefaultLifecycleProcessor.java:170)
at org.springframework.context.support.AbstractApplicationContext.start(AbstractApplicationContext.java:1459)
at smoketest.actuator.SampleActuatorApplication.main(SampleActuatorApplication.java:67)
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:287)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:467)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:256)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:201)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:965)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:619)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.actuate.autoconfigure.web.server.ChildManagementContextInitializer.onApplicationEvent(ChildManagementContextInitializer.java:86)
at org.springframework.boot.actuate.autoconfigure.web.server.ChildManagementContextInitializer.onApplicationEvent(ChildManagementContextInitializer.java:1)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:149)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:445)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:47)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:284)
... 6 more
Caused by: org.springframework.boot.web.server.PortInUseException: Port 8888 is already in use
at org.springframework.boot.web.server.PortInUseException.lambda$0(PortInUseException.java:70)
at org.springframework.boot.web.server.PortInUseException.lambda$1(PortInUseException.java:85)
at org.springframework.boot.web.server.PortInUseException.ifCausedBy(PortInUseException.java:103)
at org.springframework.boot.web.server.PortInUseException.ifPortBindingException(PortInUseException.java:82)
at org.springframework.boot.web.server.PortInUseException.throwIfPortBindingException(PortInUseException.java:69)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:228)
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:44)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:284)
... 22 more
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:235)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:286)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:214)
... 24 more
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1046)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:232)
... 26 more
Caused by: java.net.BindException: Address already in use
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:555)
at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:247)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:202)
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1280)
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1366)
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635)
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1043)
... 28 more
The restart of the main web server causes the management context, including its web server, to be refreshed again.
Comment From: sdeleuze
Thanks for the quick fix @wilkinsona, I confirm this fixes the issue.