Ensure web containers are stopped after close
Update `EmbeddedServletContainer` implementations to ensure that stop
can be called even if start has not. This allows servers that are
partially started during `initialize()` to still be shut down.
This commit fixes a regression caused by commit 0af53b361f
.
See gh-8036
Fixes gh-8224
Closes gh-8227
This commit is contained in:
parent
c06a9771c2
commit
757aa647cf
|
@ -205,9 +205,6 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
|
|||
@Override
|
||||
public void stop() {
|
||||
synchronized (this.monitor) {
|
||||
if (!this.started) {
|
||||
return;
|
||||
}
|
||||
this.started = false;
|
||||
try {
|
||||
this.server.stop();
|
||||
|
|
|
@ -279,9 +279,6 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|||
@Override
|
||||
public void stop() throws EmbeddedServletContainerException {
|
||||
synchronized (this.monitor) {
|
||||
if (!this.started) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.started = false;
|
||||
try {
|
||||
|
|
|
@ -143,6 +143,16 @@ public class JettyEmbeddedServletContainerFactoryTests
|
|||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopNoStart() throws Exception {
|
||||
JettyEmbeddedServletContainerFactory factory = getFactory();
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(exampleServletRegistration());
|
||||
this.container.stop();
|
||||
Server server = ((JettyEmbeddedServletContainer) this.container).getServer();
|
||||
assertThat(server.isStopped()).isTrue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addConnector(final int port,
|
||||
AbstractEmbeddedServletContainerFactory factory) {
|
||||
|
|
|
@ -352,6 +352,16 @@ public class TomcatEmbeddedServletContainerFactoryTests
|
|||
.doesNotContain("appears to have started a thread named [main]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopNoStart() throws Exception {
|
||||
TomcatEmbeddedServletContainerFactory factory = getFactory();
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(exampleServletRegistration());
|
||||
this.container.stop();
|
||||
Tomcat tomcat = ((TomcatEmbeddedServletContainer) this.container).getTomcat();
|
||||
assertThat(tomcat.getServer().getState()).isSameAs(LifecycleState.DESTROYED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addConnector(int port,
|
||||
AbstractEmbeddedServletContainerFactory factory) {
|
||||
|
|
Loading…
Reference in New Issue