This is an automated email from the ASF dual-hosted git repository.

earthchen pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 9d659eba44 Fix channel leakage in onConnected and onGoaway methods 
(#14100)
9d659eba44 is described below

commit 9d659eba448e70834d33cbc276181100fada104c
Author: hanpen24 <[email protected]>
AuthorDate: Wed May 8 12:36:08 2024 +0900

    Fix channel leakage in onConnected and onGoaway methods (#14100)
---
 .../remoting/transport/netty4/NettyConnectionClient.java      | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git 
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyConnectionClient.java
 
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyConnectionClient.java
index 85cd565173..5f1c9bd062 100644
--- 
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyConnectionClient.java
+++ 
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyConnectionClient.java
@@ -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));

Reply via email to