zrlw commented on code in PR #15209: URL: https://github.com/apache/dubbo/pull/15209#discussion_r1988602527
########## dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java: ########## @@ -86,79 +88,100 @@ public ChannelPipeline getPipeline() { @Override protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); - ChannelFuture future = bootstrap.connect(getConnectAddress()); + InetSocketAddress connectAddress = getConnectAddress(); + ChannelFuture future = bootstrap.connect(connectAddress); + long connectTimeout = getConnectTimeout(); + long deadline = start + connectTimeout; try { - boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); - - if (ret && future.isSuccess()) { - Channel newChannel = future.getChannel(); - newChannel.setInterestOps(Channel.OP_READ_WRITE); - try { - // Close old channel - Channel oldChannel = NettyClient.this.channel; // copy reference - if (oldChannel != null) { - try { - if (logger.isInfoEnabled()) { - logger.info("Close old netty channel " + oldChannel + " on create new netty channel " - + newChannel); + while (true) { + boolean ret = future.awaitUninterruptibly(connectTimeout, TimeUnit.MILLISECONDS); + + if (ret && future.isSuccess()) { + Channel newChannel = future.getChannel(); + newChannel.setInterestOps(Channel.OP_READ_WRITE); + try { + // copy reference + Channel oldChannel = NettyClient.this.channel; + if (oldChannel != null) { + try { + if (logger.isInfoEnabled()) { + logger.info("Close old netty channel " + oldChannel + + " on create new netty channel " + newChannel); + } + // Close old channel + oldChannel.close(); + } finally { + NettyChannel.removeChannelIfDisconnected(oldChannel); } - oldChannel.close(); - } finally { - NettyChannel.removeChannelIfDisconnected(oldChannel); } - } - } finally { - if (NettyClient.this.isClosed()) { - try { - if (logger.isInfoEnabled()) { - logger.info("Close new netty channel " + newChannel + ", because the client closed."); + } finally { + if (NettyClient.this.isClosed()) { + try { + if (logger.isInfoEnabled()) { + logger.info( + "Close new netty channel " + newChannel + ", because the client closed."); + } + newChannel.close(); + } finally { + NettyClient.this.channel = null; + NettyChannel.removeChannelIfDisconnected(newChannel); } - newChannel.close(); - } finally { - NettyClient.this.channel = null; - NettyChannel.removeChannelIfDisconnected(newChannel); + } else { + NettyClient.this.channel = newChannel; + } + } + break; + } else if (future.getCause() != null) { + Throwable cause = future.getCause(); + + if (cause instanceof ClosedChannelException) { + // Netty3.2.10 ClosedChannelException issue, see https://github.com/netty/netty/issues/138 + connectTimeout = deadline - System.currentTimeMillis(); Review Comment: @AlbumenJ connectTimeout will be recalculated at here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org