Tell what the remote address was when ConnectException occurs.
- Fixes #1082
This commit is contained in:
parent
6ed2a5d82d
commit
a5188b9d25
@ -15,11 +15,6 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.local;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.jboss.netty.channel.AbstractChannelSink;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelEvent;
|
||||
@ -32,6 +27,11 @@ import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
/**
|
||||
*/
|
||||
final class LocalClientChannelSink extends AbstractChannelSink {
|
||||
@ -101,7 +101,8 @@ final class LocalClientChannelSink extends AbstractChannelSink {
|
||||
private void connect(DefaultLocalChannel channel, ChannelFuture future, LocalAddress remoteAddress) {
|
||||
Channel remoteChannel = LocalChannelRegistry.getChannel(remoteAddress);
|
||||
if (!(remoteChannel instanceof DefaultLocalServerChannel)) {
|
||||
future.setFailure(new ConnectException("connection refused"));
|
||||
future.setFailure(new ConnectException(
|
||||
"connection refused: " + remoteAddress));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ public final class NioClientBoss extends AbstractNioSelector implements Boss {
|
||||
currentTimeNanos >= ch.connectDeadlineNanos) {
|
||||
|
||||
if (cause == null) {
|
||||
cause = new ConnectException("connection timed out");
|
||||
cause = new ConnectException("connection timed out: " + ch.requestedRemoteAddress);
|
||||
}
|
||||
|
||||
ch.connectFuture.setFailure(cause);
|
||||
@ -145,12 +145,18 @@ public final class NioClientBoss extends AbstractNioSelector implements Boss {
|
||||
|
||||
private static void connect(SelectionKey k) throws IOException {
|
||||
NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment();
|
||||
if (ch.channel.finishConnect()) {
|
||||
k.cancel();
|
||||
if (ch.timoutTimer != null) {
|
||||
ch.timoutTimer.cancel();
|
||||
try {
|
||||
if (ch.channel.finishConnect()) {
|
||||
k.cancel();
|
||||
if (ch.timoutTimer != null) {
|
||||
ch.timoutTimer.cancel();
|
||||
}
|
||||
ch.worker.register(ch, ch.connectFuture);
|
||||
}
|
||||
ch.worker.register(ch, ch.connectFuture);
|
||||
} catch (ConnectException e) {
|
||||
ConnectException newE = new ConnectException(e.getMessage() + ": " + ch.requestedRemoteAddress);
|
||||
newE.setStackTrace(e.getStackTrace());
|
||||
throw newE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,6 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFactory;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
@ -29,6 +24,12 @@ import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.Timeout;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
final class NioClientSocketChannel extends NioSocketChannel {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
@ -70,6 +71,7 @@ final class NioClientSocketChannel extends NioSocketChannel {
|
||||
|
||||
// Does not need to be volatile as it's accessed by only one thread.
|
||||
long connectDeadlineNanos;
|
||||
volatile SocketAddress requestedRemoteAddress;
|
||||
|
||||
volatile Timeout timoutTimer;
|
||||
|
||||
|
@ -25,6 +25,7 @@ import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
|
||||
@ -102,6 +103,7 @@ class NioClientSocketPipelineSink extends AbstractNioChannelSink {
|
||||
private void connect(
|
||||
final NioClientSocketChannel channel, final ChannelFuture cf,
|
||||
SocketAddress remoteAddress) {
|
||||
channel.requestedRemoteAddress = remoteAddress;
|
||||
try {
|
||||
if (channel.channel.connect(remoteAddress)) {
|
||||
channel.worker.register(channel, cf);
|
||||
@ -120,6 +122,11 @@ class NioClientSocketPipelineSink extends AbstractNioChannelSink {
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof ConnectException) {
|
||||
Throwable newT = new ConnectException(t.getMessage() + ": " + remoteAddress);
|
||||
newT.setStackTrace(t.getStackTrace());
|
||||
t = newT;
|
||||
}
|
||||
cf.setFailure(t);
|
||||
fireExceptionCaught(channel, t);
|
||||
channel.worker.close(channel, succeededFuture(channel));
|
||||
|
@ -15,12 +15,6 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.oio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.PushbackInputStream;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.ChannelEvent;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ChannelFutureListener;
|
||||
@ -31,6 +25,13 @@ import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
|
||||
import java.io.PushbackInputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
class OioClientSocketPipelineSink extends AbstractOioChannelSink {
|
||||
|
||||
private final Executor workerExecutor;
|
||||
@ -125,6 +126,13 @@ class OioClientSocketPipelineSink extends AbstractOioChannelSink {
|
||||
"Old I/O client worker (" + channel + ')'));
|
||||
workerStarted = true;
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof ConnectException) {
|
||||
if (t instanceof ConnectException) {
|
||||
Throwable newT = new ConnectException(t.getMessage() + ": " + remoteAddress);
|
||||
newT.setStackTrace(t.getStackTrace());
|
||||
t = newT;
|
||||
}
|
||||
}
|
||||
future.setFailure(t);
|
||||
fireExceptionCaught(channel, t);
|
||||
} finally {
|
||||
|
Loading…
Reference in New Issue
Block a user