You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/12/11 14:40:37 UTC

[camel] branch master updated: CAMEL-15937: camel-netty - Avoid WARN log when disconnect=true due and response received which causes callback to be triggered twice. Thanks to Nils Kremer for reporting and reproducer.

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new cdcc5b9  CAMEL-15937: camel-netty - Avoid WARN log when disconnect=true due and response received which causes callback to be triggered twice. Thanks to Nils Kremer for reporting and reproducer.
cdcc5b9 is described below

commit cdcc5b93224b1729a6c92a98e6353197283ea8a8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 11 15:25:35 2020 +0100

    CAMEL-15937: camel-netty - Avoid WARN log when disconnect=true due and response received which causes callback to be triggered twice. Thanks to Nils Kremer for reporting and reproducer.
---
 .../component/netty/handlers/ClientChannelHandler.java      | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
index dd9c6e0..ee7a43c 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
@@ -42,6 +42,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {
     private final NettyProducer producer;
     private volatile boolean messageReceived;
     private volatile boolean exceptionHandled;
+    private volatile boolean disconnecting;
 
     public ClientChannelHandler(NettyProducer producer) {
         this.producer = producer;
@@ -55,6 +56,11 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {
         // to keep track of open sockets
         producer.getAllChannels().add(ctx.channel());
 
+        // reset flags
+        disconnecting = false;
+        messageReceived = false;
+        exceptionHandled = false;
+
         super.channelActive(ctx);
     }
 
@@ -113,7 +119,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {
         // to keep track of open sockets
         producer.getAllChannels().remove(ctx.channel());
 
-        if (exchange != null) {
+        if (exchange != null && !disconnecting) {
             // this channel is maybe closing graceful and the exchange is already done
             // and if so we should not trigger an exception
             boolean doneUoW = exchange.getUnitOfWork() == null;
@@ -138,6 +144,9 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {
             }
         }
 
+        // reset flag as the channel has been disconnected (state is now inactive)
+        disconnecting = false;
+
         // make sure the event can be processed by other handlers
         super.channelInactive(ctx);
     }
@@ -211,6 +220,8 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Closing channel when complete at address: {}", producer.getConfiguration().getAddress());
                 }
+                // flag to know we are forcing a disconnect
+                disconnecting = true;
                 NettyHelper.close(ctx.channel());
             }
         } finally {