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

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


The following commit(s) were added to refs/heads/3.3 by this push:
     new 96556af28b Log warning message at method exceptionCaught of Netty 
handlers (#15272)
96556af28b is described below

commit 96556af28b1c94c0c97cfba7c934d074208291a2
Author: zrlw <[email protected]>
AuthorDate: Tue Apr 1 10:11:54 2025 +0800

    Log warning message at method exceptionCaught of Netty handlers (#15272)
---
 .../remoting/transport/netty/NettyHandler.java     | 56 +++++++++++++++-------
 .../transport/netty4/NettyClientHandler.java       | 23 +++++++--
 .../transport/netty4/NettyServerHandler.java       | 28 ++++++++---
 3 files changed, 79 insertions(+), 28 deletions(-)

diff --git 
a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHandler.java
 
b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHandler.java
index e9e62b7bb9..21e05a58f4 100644
--- 
a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHandler.java
+++ 
b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHandler.java
@@ -17,7 +17,7 @@
 package org.apache.dubbo.remoting.transport.netty;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.remoting.Channel;
@@ -34,13 +34,15 @@ import org.jboss.netty.channel.ExceptionEvent;
 import org.jboss.netty.channel.MessageEvent;
 import org.jboss.netty.channel.SimpleChannelHandler;
 
+import static 
org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
+
 /**
  * NettyHandler
  */
 @Sharable
 public class NettyHandler extends SimpleChannelHandler {
 
-    private static final Logger logger = 
LoggerFactory.getLogger(NettyHandler.class);
+    private static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(NettyHandler.class);
 
     private final Map<String, Channel> channels = new ConcurrentHashMap<>(); 
// <ip:port, channel>
 
@@ -65,39 +67,43 @@ public class NettyHandler extends SimpleChannelHandler {
 
     @Override
     public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent 
e) throws Exception {
-        NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), 
url, handler);
+        org.jboss.netty.channel.Channel ch = ctx.getChannel();
+        NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
         try {
             if (channel != null) {
-                channels.put(
-                        NetUtils.toAddressString(
-                                (InetSocketAddress) 
ctx.getChannel().getRemoteAddress()),
-                        channel);
+                channels.put(NetUtils.toAddressString((InetSocketAddress) 
ch.getRemoteAddress()), channel);
             }
             handler.connected(channel);
         } finally {
-            NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
+            NettyChannel.removeChannelIfDisconnected(ch);
         }
 
         if (logger.isInfoEnabled() && channel != null) {
-            logger.info("The connection between " + channel.getRemoteAddress() 
+ " and " + channel.getLocalAddress()
-                    + " is established");
+            logger.info(
+                    "The connection {} between {} and {} is established.",
+                    ch,
+                    channel.getRemoteAddress(),
+                    channel.getLocalAddress());
         }
     }
 
     @Override
     public void channelDisconnected(ChannelHandlerContext ctx, 
ChannelStateEvent e) throws Exception {
-        NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), 
url, handler);
+        org.jboss.netty.channel.Channel ch = ctx.getChannel();
+        NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
         try {
-            channels.remove(NetUtils.toAddressString(
-                    (InetSocketAddress) ctx.getChannel().getRemoteAddress()));
+            channels.remove(NetUtils.toAddressString((InetSocketAddress) 
ch.getRemoteAddress()));
             handler.disconnected(channel);
         } finally {
-            NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
+            NettyChannel.removeChannelIfDisconnected(ch);
         }
 
         if (logger.isInfoEnabled()) {
-            logger.info("The connection between " + channel.getRemoteAddress() 
+ " and " + channel.getLocalAddress()
-                    + " is disconnected");
+            logger.info(
+                    "The connection {} between {} and {} is disconnected.",
+                    ch,
+                    channel.getRemoteAddress(),
+                    channel.getLocalAddress());
         }
     }
 
@@ -124,11 +130,25 @@ public class NettyHandler extends SimpleChannelHandler {
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) 
throws Exception {
-        NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), 
url, handler);
+        org.jboss.netty.channel.Channel ch = ctx.getChannel();
+        NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
         try {
             handler.caught(channel, e.getCause());
         } finally {
-            NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
+            NettyChannel.removeChannelIfDisconnected(ch);
+        }
+
+        if (logger.isWarnEnabled()) {
+            logger.warn(
+                    TRANSPORT_UNEXPECTED_EXCEPTION,
+                    "",
+                    "",
+                    channel == null
+                            ? String.format("The connection %s has 
exception.", ch)
+                            : String.format(
+                                    "The connection %s between %s and %s has 
exception.",
+                                    ch, channel.getRemoteAddress(), 
channel.getLocalAddress()),
+                    e.getCause());
         }
     }
 }
diff --git 
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClientHandler.java
 
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClientHandler.java
index 449b39385a..1f0e48fc5b 100644
--- 
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClientHandler.java
+++ 
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClientHandler.java
@@ -18,7 +18,7 @@ package org.apache.dubbo.remoting.transport.netty4;
 
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.Version;
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.remoting.ChannelHandler;
 import org.apache.dubbo.remoting.exchange.Request;
@@ -30,13 +30,14 @@ import io.netty.channel.ChannelPromise;
 import io.netty.handler.timeout.IdleStateEvent;
 
 import static 
org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
+import static 
org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
 
 /**
  * NettyClientHandler
  */
 @io.netty.channel.ChannelHandler.Sharable
 public class NettyClientHandler extends ChannelDuplexHandler {
-    private static final Logger logger = 
LoggerFactory.getLogger(NettyClientHandler.class);
+    private static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(NettyClientHandler.class);
 
     private final URL url;
 
@@ -122,11 +123,25 @@ public class NettyClientHandler extends 
ChannelDuplexHandler {
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 
throws Exception {
-        NettyChannel channel = NettyChannel.getOrAddChannel(ctx.channel(), 
url, handler);
+        Channel ch = ctx.channel();
+        NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
         try {
             handler.caught(channel, cause);
         } finally {
-            NettyChannel.removeChannelIfDisconnected(ctx.channel());
+            NettyChannel.removeChannelIfDisconnected(ch);
+        }
+
+        if (logger.isWarnEnabled()) {
+            logger.warn(
+                    TRANSPORT_UNEXPECTED_EXCEPTION,
+                    "",
+                    "",
+                    channel == null
+                            ? String.format("The connection %s has 
exception.", ch)
+                            : String.format(
+                                    "The connection %s of %s -> %s has 
exception.",
+                                    ch, channel.getLocalAddressKey(), 
channel.getRemoteAddressKey()),
+                    cause);
         }
     }
 }
diff --git 
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServerHandler.java
 
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServerHandler.java
index e42fbcd7ab..9711f1dff4 100644
--- 
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServerHandler.java
+++ 
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServerHandler.java
@@ -17,7 +17,7 @@
 package org.apache.dubbo.remoting.transport.netty4;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.remoting.Channel;
@@ -36,12 +36,14 @@ import io.netty.handler.ssl.SslHandshakeCompletionEvent;
 import io.netty.handler.timeout.IdleStateEvent;
 import io.netty.util.AttributeKey;
 
+import static 
org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_UNEXPECTED_EXCEPTION;
+
 /**
  * NettyServerHandler.
  */
 @io.netty.channel.ChannelHandler.Sharable
 public class NettyServerHandler extends ChannelDuplexHandler {
-    private static final Logger logger = 
LoggerFactory.getLogger(NettyServerHandler.class);
+    private static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(NettyServerHandler.class);
     /**
      * the cache for alive worker channel.
      * <ip:port, dubbo channel>
@@ -82,8 +84,8 @@ public class NettyServerHandler extends ChannelDuplexHandler {
             logger.info(
                     "The connection {} of {} -> {} is established.",
                     ch,
-                    channel.getLocalAddressKey(),
-                    channel.getRemoteAddressKey());
+                    channel.getRemoteAddressKey(),
+                    channel.getLocalAddressKey());
         }
     }
 
@@ -148,11 +150,25 @@ public class NettyServerHandler extends 
ChannelDuplexHandler {
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 
throws Exception {
-        NettyChannel channel = NettyChannel.getOrAddChannel(ctx.channel(), 
url, handler);
+        io.netty.channel.Channel ch = ctx.channel();
+        NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
         try {
             handler.caught(channel, cause);
         } finally {
-            NettyChannel.removeChannelIfDisconnected(ctx.channel());
+            NettyChannel.removeChannelIfDisconnected(ch);
+        }
+
+        if (logger.isWarnEnabled()) {
+            logger.warn(
+                    TRANSPORT_UNEXPECTED_EXCEPTION,
+                    "",
+                    "",
+                    channel == null
+                            ? String.format("The connection %s has 
exception.", ch)
+                            : String.format(
+                                    "The connection %s of %s -> %s has 
exception.",
+                                    ch, channel.getRemoteAddressKey(), 
channel.getLocalAddressKey()),
+                    cause);
         }
     }
 }

Reply via email to