CAMEL-9527: camel netty client/producer should graceful handle channel being closed/inactive without causing an exception after the exchange is done.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8881b79d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8881b79d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8881b79d Branch: refs/heads/camel-2.15.x Commit: 8881b79d4122b87d47962110fbd44607530b460c Parents: f0a65e6 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Jan 24 12:49:09 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Jan 24 12:50:24 2016 +0100 ---------------------------------------------------------------------- .../camel/component/netty/handlers/ClientChannelHandler.java | 7 ++++++- .../camel/component/netty4/handlers/ClientChannelHandler.java | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/8881b79d/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java ---------------------------------------------------------------------- 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 475e14b..9c370e2 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 @@ -109,7 +109,11 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler { // to keep track of open sockets producer.getAllChannels().remove(ctx.getChannel()); - if (producer.getConfiguration().isSync() && !messageReceived && !exceptionHandled) { + // 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; + + if (producer.getConfiguration().isSync() && !doneUoW && !messageReceived && !exceptionHandled) { // To avoid call the callback.done twice exceptionHandled = true; // session was closed but no message received. This could be because the remote server had an internal error @@ -121,6 +125,7 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler { // signal callback callback.done(false); } + // make sure the event can be processed by other handlers super.channelClosed(ctx, e); } http://git-wip-us.apache.org/repos/asf/camel/blob/8881b79d/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java index 937d2d0..25530ef 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ClientChannelHandler.java @@ -106,8 +106,12 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> { // to keep track of open sockets producer.getAllChannels().remove(ctx.channel()); + // 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; + NettyConfiguration configuration = producer.getConfiguration(); - if (configuration.isSync() && !messageReceived && !exceptionHandled) { + if (configuration.isSync() && !doneUoW && !messageReceived && !exceptionHandled) { // To avoid call the callback.done twice exceptionHandled = true; // session was closed but no message received. This could be because the remote server had an internal error