Merge branch '1.5.x'

pull/10601/head
Andy Wilkinson 7 years ago
commit bcfb1d17b1

@ -159,20 +159,36 @@ public class UndertowServletWebServer implements WebServer {
.info("Undertow started on port(s) " + getPortsDescription());
}
catch (Exception ex) {
if (findBindException(ex) != null) {
List<Port> failedPorts = getConfiguredPorts();
List<Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
try {
if (findBindException(ex) != null) {
List<Port> failedPorts = getConfiguredPorts();
List<Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
}
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
finally {
stopSilently();
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
}
}
private void stopSilently() {
try {
if (this.undertow != null) {
this.undertow.stop();
}
}
catch (Exception ex) {
// Ignore
}
}
private BindException findBindException(Exception ex) {
Throwable candidate = ex;
while (candidate != null) {

@ -88,20 +88,36 @@ public class UndertowWebServer implements WebServer {
.info("Undertow started on port(s) " + getPortsDescription());
}
catch (Exception ex) {
if (findBindException(ex) != null) {
List<UndertowWebServer.Port> failedPorts = getConfiguredPorts();
List<UndertowWebServer.Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
try {
if (findBindException(ex) != null) {
List<UndertowWebServer.Port> failedPorts = getConfiguredPorts();
List<UndertowWebServer.Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
}
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
finally {
stopSilently();
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
}
}
private void stopSilently() {
try {
if (this.undertow != null) {
this.undertow.stop();
}
}
catch (Exception ex) {
// Ignore
}
}
private BindException findBindException(Exception ex) {
Throwable candidate = ex;
while (candidate != null) {

@ -303,6 +303,9 @@ public class UndertowServletWebServerFactoryTests
int blockedPort) {
assertThat(ex).isInstanceOf(PortInUseException.class);
assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
Object undertow = ReflectionTestUtils.getField(this.webServer, "undertow");
Object worker = ReflectionTestUtils.getField(undertow, "worker");
assertThat(worker).isNull();
}
}

Loading…
Cancel
Save