From 8227a7f69b96865f4a037f23f8925f5b529f9b4a Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Tue, 26 May 2020 14:59:36 +0800 Subject: [PATCH] polish #1150 --- .../client/ForwardClientSocketClientHandler.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java index ac477c422..ffd8300af 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java @@ -11,6 +11,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelPromise; import io.netty.channel.EventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.nio.NioEventLoopGroup; @@ -34,6 +35,7 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle private static final Logger logger = LoggerFactory.getLogger(ForwardClientSocketClientHandler.class); + private ChannelPromise handshakeFuture; private final URI localServerURI; public ForwardClientSocketClientHandler(URI localServerURI) { @@ -83,8 +85,8 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle }); Channel localChannel = b.connect(localServerURI.getHost(), localServerURI.getPort()).sync().channel(); - localFrameHandler.handshakeFuture() - .addListener(new GenericFutureListener() { + this.handshakeFuture = localFrameHandler.handshakeFuture(); + handshakeFuture.addListener(new GenericFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { ChannelPipeline pipeline = future.channel().pipeline(); @@ -93,7 +95,7 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle } }); - localFrameHandler.handshakeFuture().sync(); + handshakeFuture.sync(); ctx.pipeline().remove(ForwardClientSocketClientHandler.this); ctx.pipeline().addLast(new RelayHandler(localChannel)); logger.info("ForwardClientSocketClientHandler connect local arthas server success"); @@ -105,7 +107,10 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - cause.printStackTrace(); + logger.error("ForwardClientSocketClient channel: {}" , ctx.channel(), cause); + if (!handshakeFuture.isDone()) { + handshakeFuture.setFailure(cause); + } ctx.close(); } }