From c44be8e468500ee5a4ba0f1bd6eeca8d3ceb2940 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 4 Aug 2014 09:37:49 +0200 Subject: [PATCH] [#2713] Always use correct remote address in ConnectTimeoutException Motivation: As we cached ConnectTimeoutException we sometimes ended up using the wrong remote address in the exception message. Modifications: Always create a new ConnectTimeException and so make sure we use the connect remote address. This has a bit more overhead because of fill in the stacktrace everytime but as this only happens on connection timeouts it should be ok. Result: Always include the correct remote address in ConnectTimeoutException. --- .../jboss/netty/channel/socket/nio/NioClientBoss.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioClientBoss.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioClientBoss.java index 3195f58658..a7250fff80 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioClientBoss.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioClientBoss.java @@ -115,7 +115,6 @@ public final class NioClientBoss extends AbstractNioSelector implements Boss { } private static void processConnectTimeout(Set keys, long currentTimeNanos) { - ConnectException cause = null; for (SelectionKey k: keys) { if (!k.isValid()) { // Comment the close call again as it gave us major problems @@ -133,9 +132,12 @@ public final class NioClientBoss extends AbstractNioSelector implements Boss { if (ch.connectDeadlineNanos > 0 && currentTimeNanos >= ch.connectDeadlineNanos) { - if (cause == null) { - cause = new ConnectTimeoutException("connection timed out: " + ch.requestedRemoteAddress); - } + // Create a new ConnectException everytime and not cache it as otherwise we end up with + // using the wrong remoteaddress in the ConnectException message. + // + // See https://github.com/netty/netty/issues/2713 + ConnectException cause = + new ConnectTimeoutException("connection timed out: " + ch.requestedRemoteAddress); ch.connectFuture.setFailure(cause); fireExceptionCaught(ch, cause);