Commit bcfb1d17 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '1.5.x'

parents 325b2b09 c44b912f
...@@ -159,6 +159,7 @@ public class UndertowServletWebServer implements WebServer { ...@@ -159,6 +159,7 @@ public class UndertowServletWebServer implements WebServer {
.info("Undertow started on port(s) " + getPortsDescription()); .info("Undertow started on port(s) " + getPortsDescription());
} }
catch (Exception ex) { catch (Exception ex) {
try {
if (findBindException(ex) != null) { if (findBindException(ex) != null) {
List<Port> failedPorts = getConfiguredPorts(); List<Port> failedPorts = getConfiguredPorts();
List<Port> actualPorts = getActualPorts(); List<Port> actualPorts = getActualPorts();
...@@ -170,6 +171,21 @@ public class UndertowServletWebServer implements WebServer { ...@@ -170,6 +171,21 @@ public class UndertowServletWebServer implements WebServer {
} }
throw new WebServerException("Unable to start embedded Undertow", ex); throw new WebServerException("Unable to start embedded Undertow", ex);
} }
finally {
stopSilently();
}
}
}
}
private void stopSilently() {
try {
if (this.undertow != null) {
this.undertow.stop();
}
}
catch (Exception ex) {
// Ignore
} }
} }
......
...@@ -88,6 +88,7 @@ public class UndertowWebServer implements WebServer { ...@@ -88,6 +88,7 @@ public class UndertowWebServer implements WebServer {
.info("Undertow started on port(s) " + getPortsDescription()); .info("Undertow started on port(s) " + getPortsDescription());
} }
catch (Exception ex) { catch (Exception ex) {
try {
if (findBindException(ex) != null) { if (findBindException(ex) != null) {
List<UndertowWebServer.Port> failedPorts = getConfiguredPorts(); List<UndertowWebServer.Port> failedPorts = getConfiguredPorts();
List<UndertowWebServer.Port> actualPorts = getActualPorts(); List<UndertowWebServer.Port> actualPorts = getActualPorts();
...@@ -99,6 +100,21 @@ public class UndertowWebServer implements WebServer { ...@@ -99,6 +100,21 @@ public class UndertowWebServer implements WebServer {
} }
throw new WebServerException("Unable to start embedded Undertow", ex); throw new WebServerException("Unable to start embedded Undertow", ex);
} }
finally {
stopSilently();
}
}
}
}
private void stopSilently() {
try {
if (this.undertow != null) {
this.undertow.stop();
}
}
catch (Exception ex) {
// Ignore
} }
} }
......
...@@ -303,6 +303,9 @@ public class UndertowServletWebServerFactoryTests ...@@ -303,6 +303,9 @@ public class UndertowServletWebServerFactoryTests
int blockedPort) { int blockedPort) {
assertThat(ex).isInstanceOf(PortInUseException.class); assertThat(ex).isInstanceOf(PortInUseException.class);
assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort); assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
Object undertow = ReflectionTestUtils.getField(this.webServer, "undertow");
Object worker = ReflectionTestUtils.getField(undertow, "worker");
assertThat(worker).isNull();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment