Skip to content

Commit 6a05a9e

Browse files
authored
[Chore] Remove channelsLock on onChannelInactive to avoid deadlock (#17084)
1 parent eefb1fa commit 6a05a9e

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/client/NettyClientHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public NettyClientHandler(NettyRemotingClient nettyRemotingClient) {
4343

4444
@Override
4545
public void channelInactive(ChannelHandlerContext ctx) {
46-
nettyRemotingClient.closeChannel(ChannelUtils.toAddress(ctx.channel()));
46+
log.info("Channel inactive: {}", ctx.channel());
47+
nettyRemotingClient.onChannelInactive(ChannelUtils.toAddress(ctx.channel()));
4748
ctx.channel().close();
4849
}
4950

@@ -65,8 +66,8 @@ private void processReceived(final Transporter transporter) {
6566

6667
@Override
6768
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
68-
log.error("NettyClientHandler catch an exception : {}", cause.getMessage(), cause);
69-
nettyRemotingClient.closeChannel(ChannelUtils.toAddress(ctx.channel()));
69+
log.error("NettyClientHandler catch an exception on channel: {}", ctx.channel(), cause);
70+
nettyRemotingClient.onChannelInactive(ChannelUtils.toAddress(ctx.channel()));
7071
ctx.channel().close();
7172
}
7273

dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/client/NettyRemotingClient.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,13 @@ private void closeChannels() {
247247
try {
248248
channelsLock.lock();
249249
channels.values().forEach(Channel::close);
250+
channels.clear();
250251
} finally {
251252
channelsLock.unlock();
252253
}
253254
}
254255

255-
public void closeChannel(Host host) {
256-
try {
257-
channelsLock.lock();
258-
Channel channel = this.channels.remove(host);
259-
if (channel != null) {
260-
channel.close();
261-
}
262-
} finally {
263-
channelsLock.unlock();
264-
}
256+
public void onChannelInactive(final Host host) {
257+
channels.remove(host);
265258
}
266259
}

0 commit comments

Comments
 (0)