From 215bf562aaa3353787c2e963c5b09ea39274f3b1 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 31 Mar 2011 14:33:11 +0000 Subject: [PATCH] Improved exception handling during connect to remote server. git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2942 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../jetty/server/handler/ConnectHandler.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java index 5ba8c8309c6..e59e7245db4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java @@ -329,13 +329,29 @@ public class ConnectHandler extends HandlerWrapper */ protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException { - _logger.debug("Establishing connection to {}:{}", host, port); - // Connect to remote server SocketChannel channel = SocketChannel.open(); - channel.socket().setTcpNoDelay(true); - channel.socket().connect(new InetSocketAddress(host, port), getConnectTimeout()); - _logger.debug("Established connection to {}:{}", host, port); - return channel; + try + { + // Connect to remote server + _logger.debug("Establishing connection to {}:{}", host, port); + channel.socket().setTcpNoDelay(true); + channel.socket().connect(new InetSocketAddress(host, port), getConnectTimeout()); + _logger.debug("Established connection to {}:{}", host, port); + return channel; + } + catch (IOException x) + { + _logger.debug("Failed to establish connection to " + host + ":" + port, x); + try + { + channel.close(); + } + catch (IOException xx) + { + Log.ignore(xx); + } + throw x; + } } protected void prepareContext(HttpServletRequest request, ConcurrentMap context)