diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java index 2e6cc84df7..773683bf2f 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -34,6 +34,7 @@ import io.netty.util.internal.InternalThreadLocalMap; import io.netty.util.internal.OneTimeTask; import io.netty.util.internal.PlatformDependent; +import java.net.ConnectException; import java.net.SocketAddress; import java.nio.channels.AlreadyConnectedException; import java.nio.channels.ClosedChannelException; @@ -476,7 +477,7 @@ public class LocalChannel extends AbstractChannel { Channel boundChannel = LocalChannelRegistry.get(remoteAddress); if (!(boundChannel instanceof LocalServerChannel)) { - Exception cause = new ChannelException("connection refused"); + Exception cause = new ConnectException("connection refused: " + remoteAddress); safeSetFailure(promise, cause); close(voidPromise()); return; diff --git a/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java b/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java index 3b9c86aa75..8eac9f7415 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java +++ b/transport/src/test/java/io/netty/channel/local/LocalChannelTest.java @@ -41,6 +41,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import java.net.ConnectException; import java.nio.channels.ClosedChannelException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadFactory; @@ -862,6 +863,15 @@ public class LocalChannelTest { } } + @Test(expected = ConnectException.class) + public void testConnectionRefused() { + Bootstrap sb = new Bootstrap(); + sb.group(group1) + .channel(LocalChannel.class) + .handler(new TestHandler()) + .connect(LocalAddress.ANY).syncUninterruptibly(); + } + private static final class LatchChannelFutureListener extends CountDownLatch implements ChannelFutureListener { public LatchChannelFutureListener(int count) { super(count);