You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2022/07/08 20:14:50 UTC

[GitHub] [ratis] szetszwo commented on a diff in pull request #676: RATIS-1618. Resolve the stream client concurrent reconnection problem

szetszwo commented on code in PR #676:
URL: https://github.com/apache/ratis/pull/676#discussion_r917110738


##########
ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientStreamRpc.java:
##########
@@ -213,9 +224,11 @@ private ChannelFuture reconnect() {
     void close() {
       final ChannelFuture previous = ref.getAndSet(null);
       if (previous != null) {
-        previous.channel().close();
+        // wait channel closed, do shutdown workerGroup
+        previous.channel().close().addListener((future) -> workerGroup.shutdownGracefully());
+      } else {
+        workerGroup.shutdownGracefully();

Review Comment:
   The else is not needed since previous == null means already closed.



##########
ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientStreamRpc.java:
##########
@@ -201,7 +202,17 @@ void scheduleReconnect(String message, Throwable cause) {
       getWorkerGroup().schedule(this::reconnect, RECONNECT.getDuration(), RECONNECT.getUnit());
     }
 
-    private ChannelFuture reconnect() {
+    private synchronized ChannelFuture reconnect() {
+      // concurrent reconnect double check
+      ChannelFuture channelFuture = ref.get();
+      if (channelFuture != null) {
+        Channel channel = channelFuture.syncUninterruptibly().channel();
+        if (channel.isActive()) {
+          LOG.info("{} is already connect use exists channel {}", this, channel);

Review Comment:
   Remove LOG.info since this is a client code.



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org