Use ConnectException when connection failed for LocalChannel
Motivation: To be more consistent we should use ConnectException when we fail the connect attempt because no LocalServerChannel exists with the given address. Modifications: Use correct exception. Result: More consistent handling of connection refused between different transports.
This commit is contained in:
parent
219bc6474e
commit
7bfcb5520b
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user