HuangZhenQiu commented on a change in pull request #11541:
URL: https://github.com/apache/flink/pull/11541#discussion_r434978499



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/PartitionRequestClientFactory.java
##########
@@ -131,6 +138,43 @@ void destroyPartitionRequestClient(ConnectionID 
connectionId, PartitionRequestCl
                clients.remove(connectionId, client);
        }
 
+       private void connectChannelWithRetry(ConnectingChannel 
connectingChannel,
+                                                                               
 ConnectionID connectionId, boolean needConnect)
+               throws IOException, InterruptedException {
+               int count = 0;
+               Exception exception = null;
+               do {
+                       try {
+                               if (needConnect) {
+                                       LOG.info("Connecting to {} at {} 
attempt", connectionId.getAddress(), count);
+                                       
nettyClient.connect(connectionId.getAddress()).addListener(connectingChannel);
+                               }
+
+                               NettyPartitionRequestClient client = 
connectingChannel.waitForChannel();
+
+                               clients.replace(connectionId, 
connectingChannel, client);
+                               return;
+                       } catch (IOException | ChannelException e) {
+                               LOG.error("Failed {} times to connect to {}", 
count, connectionId.getAddress(), e);
+                               ConnectingChannel newConnectingChannel = new 
ConnectingChannel(connectionId, this);
+                               clients.replace(connectionId, 
connectingChannel, newConnectingChannel);
+                               Object old = clients.get(connectionId);
+                               if (old instanceof ConnectingChannel) {
+                                       connectingChannel = (ConnectingChannel) 
old;
+                               } else {
+                                       return;
+                               }
+
+                               exception = e;
+                       }
+                       count++;
+               } while (count <= retryNumber);

Review comment:
       Add a multiple thread test case for client creation.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to