diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index 2280d3c299e..c96f0599343 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -500,7 +500,9 @@ public class HttpClient extends ContainerLifeCycle Future result = new ConnectionCallback(destination, promise); selectorManager.connect(channel, result); } - catch (IOException x) + // Must catch all exceptions, since some like + // UnresolvedAddressException are not IOExceptions. + catch (Exception x) { if (channel != null) close(channel); diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index 1c78deb647e..bb9bea6d97e 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -18,14 +18,13 @@ package org.eclipse.jetty.client; -import static java.nio.file.StandardOpenOption.CREATE; - import java.io.IOException; import java.io.OutputStream; import java.net.HttpCookie; import java.net.URI; import java.net.URLEncoder; import java.nio.ByteBuffer; +import java.nio.channels.UnresolvedAddressException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -38,7 +37,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; import java.util.zip.GZIPOutputStream; - import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -61,6 +59,8 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; +import static java.nio.file.StandardOpenOption.CREATE; + public class HttpClientTest extends AbstractHttpClientServerTest { public HttpClientTest(SslContextFactory sslContextFactory) @@ -715,4 +715,24 @@ public class HttpClientTest extends AbstractHttpClientServerTest Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(length, response.getContent().length); } + + @Test + public void testConnectThrowsUnresolvedAddressException() throws Exception + { + start(new EmptyServerHandler()); + + final CountDownLatch latch = new CountDownLatch(1); + client.newRequest("idontexist", 80) + .send(new Response.CompleteListener() + { + @Override + public void onComplete(Result result) + { + Assert.assertTrue(result.isFailed()); + Assert.assertTrue(result.getFailure() instanceof UnresolvedAddressException); + latch.countDown(); + } + }); + Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); + } }