Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x ba737e77e -> 8a0cd0d0f


CAMEL-8949 - netty 3 doesn't handle TCP RST


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8a0cd0d0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8a0cd0d0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8a0cd0d0

Branch: refs/heads/camel-2.15.x
Commit: 8a0cd0d0f2ccf82db6c47648dd982fa1a24b6e5c
Parents: ba737e7
Author: Jonathan Anstey <jans...@gmail.com>
Authored: Fri Jul 10 11:21:57 2015 -0230
Committer: Jonathan Anstey <jans...@gmail.com>
Committed: Fri Jul 10 11:22:30 2015 -0230

----------------------------------------------------------------------
 .../HttpServerMultiplexChannelHandler.java      | 31 +++++++++++++-------
 1 file changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8a0cd0d0/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index 2c1a753..2bcac76 100644
--- 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.netty.http.handlers;
 
+import java.io.IOException;
 import java.nio.channels.ClosedChannelException;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -132,17 +133,25 @@ public class HttpServerMultiplexChannelHandler extends 
SimpleChannelUpstreamHand
                 LOG.debug("Channel already closed. Ignoring this exception.");
                 return;
             } else {
-                // we cannot throw the exception here
-                LOG.warn("HttpServerChannelHandler is not found as attachment 
to handle exception, send 404 back to the client.", e.getCause());
-                // Now we just send 404 back to the client
-                HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
NOT_FOUND);
-                response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
-                response.headers().set(Exchange.CONTENT_LENGTH, 0);
-                // Here we don't want to expose the exception detail to the 
client
-                response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
-                ctx.getChannel().write(response).syncUninterruptibly();
-                // close the channel after send error message
-                ctx.getChannel().close();
+                if ("Broken pipe".equals(e.getCause().getMessage())) {
+                    // Can't recover channel at this point. Only valid thing 
to do is close. A TCP RST is a possible cause for this.
+                    // Note that trying to write to channel in this state will 
cause infinite recursion in netty 3.x
+                    LOG.debug("Channel pipe is broken. Closing channel now.", 
e);                    
+                    ctx.getChannel().close();
+                } else {
+                    // we cannot throw the exception here
+                    LOG.warn("HttpServerChannelHandler is not found as 
attachment to handle exception, send 404 back to the client.", e.getCause());
+                    // Now we just send 404 back to the client
+                    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
NOT_FOUND);
+                    response.headers().set(Exchange.CONTENT_TYPE, 
"text/plain");
+                    response.headers().set(Exchange.CONTENT_LENGTH, 0);
+                    // Here we don't want to expose the exception detail to 
the client
+                    response.setContent(ChannelBuffers.copiedBuffer(new 
byte[]{}));                
+                    
+                    ctx.getChannel().write(response).syncUninterruptibly();
+                    // close the channel after send error message
+                    ctx.getChannel().close();
+                }
             }
         }
     }

Reply via email to