dawidwys commented on a change in pull request #15633:
URL: https://github.com/apache/flink/pull/15633#discussion_r614314772
##########
File path:
flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/networking/NetworkFailureHandler.java
##########
@@ -48,6 +48,9 @@
private static final Logger LOG =
LoggerFactory.getLogger(NetworkFailureHandler.class);
private static final String TARGET_CHANNEL_HANDLER_NAME =
"target_channel_handler";
+ // They key set of this map contains the channels that are being closed.
This is needed to
+ // prevent closeOnFlush() from being called recursively.
+ private static final Map<Channel, Channel> channelsBeingClosed = new
ConcurrentHashMap<>();
Review comment:
How about we use:
```
private static final Set<Channel> channelsBeingClosed =
ConcurrentHashMap.newKeySet();
```
##########
File path:
flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/networking/NetworkFailureHandler.java
##########
@@ -73,8 +76,10 @@ public NetworkFailureHandler(
/** Closes the specified channel after all queued write requests are
flushed. */
static void closeOnFlush(Channel channel) {
- if (channel.isConnected()) {
+ if (channel.isConnected() &&
!channelsBeingClosed.containsKey(channel)) {
+ channelsBeingClosed.put(channel, channel);
channel.write(ChannelBuffers.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
+ channelsBeingClosed.remove(channel);
Review comment:
Shouldn't we remove it only when we actually close the channel?
Something like:
```
/** Closes the specified channel after all queued write requests are
flushed. */
static void closeOnFlush(Channel channel) {
if (channel.isConnected() && !channelsBeingClosed.contains(channel))
{
channelsBeingClosed.add(channel);
channel.write(ChannelBuffers.EMPTY_BUFFER).addListener(CLOSE_WITH_BOOKKEEPING);
}
}
private static final ChannelFutureListener CLOSE_WITH_BOOKKEEPING =
future ->
future.getChannel()
.close()
.addListener(
closedChannel ->
channelsBeingClosed.remove(closedChannel.getChannel()));
```
--
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]