Skip to content

Commit 30de75c

Browse files
committed
Ensure that Jetty is completely stopped when it fails to start
Closes gh-12735
1 parent 399455f commit 30de75c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -155,9 +155,11 @@ public void start() throws EmbeddedServletContainerException {
155155
.info("Jetty started on port(s) " + getActualPortsDescription());
156156
}
157157
catch (EmbeddedServletContainerException ex) {
158+
stopSilently();
158159
throw ex;
159160
}
160161
catch (Exception ex) {
162+
stopSilently();
161163
throw new EmbeddedServletContainerException(
162164
"Unable to start embedded Jetty servlet container", ex);
163165
}

spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,16 @@ public void destroy() {
357357

358358
});
359359
this.thrown.expect(EmbeddedServletContainerException.class);
360-
factory.getEmbeddedServletContainer().start();
360+
JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) factory
361+
.getEmbeddedServletContainer();
362+
try {
363+
jettyContainer.start();
364+
}
365+
finally {
366+
QueuedThreadPool threadPool = (QueuedThreadPool) jettyContainer.getServer()
367+
.getThreadPool();
368+
assertThat(threadPool.isRunning()).isFalse();
369+
}
361370
}
362371

363372
@Test

0 commit comments

Comments
 (0)