Fix channel leakage in onConnected and onGoaway methods (#14100)

This commit is contained in:
hanpen24 2024-05-08 12:36:08 +09:00 committed by GitHub
parent 7f6decaf19
commit 9d659eba44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 0 deletions

View File

@ -236,6 +236,13 @@ public class NettyConnectionClient extends AbstractConnectionClient {
}
return;
}
// Close the existing channel before setting a new channel
final io.netty.channel.Channel current = getNettyChannel();
if (current != null) {
current.close();
}
this.channel.set(nettyChannel);
// This indicates that the connection is available.
if (this.connectingPromise.get() != null) {
@ -254,6 +261,10 @@ public class NettyConnectionClient extends AbstractConnectionClient {
}
io.netty.channel.Channel nettyChannel = (io.netty.channel.Channel) channel;
if (this.channel.compareAndSet(nettyChannel, null)) {
// Ensure the channel is closed
if (nettyChannel.isOpen()) {
nettyChannel.close();
}
NettyChannel.removeChannelIfDisconnected(nettyChannel);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("%s goaway", this));