From f2bf8c277b5a0156209531e9ff69df56b5c4a666 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 14 Oct 2011 12:45:41 +0200 Subject: [PATCH] 360938 Connections closed after a while. Resetting _total_no_progress when progress is made, to avoid that the endpoint is closed after a while of normal activity. --- .../jetty/server/AsyncHttpConnection.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java index 9a8f02b8dbb..4d72d8feb19 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java @@ -7,7 +7,6 @@ import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.AsyncEndPoint; import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.io.nio.ChannelEndPoint; import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -16,7 +15,7 @@ public class AsyncHttpConnection extends HttpConnection { private final static int NO_PROGRESS_INFO = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_INFO",100); private final static int NO_PROGRESS_CLOSE = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_CLOSE",200); - + private static final Logger LOG = Log.getLogger(AsyncHttpConnection.class); private int _total_no_progress; @@ -28,26 +27,26 @@ public class AsyncHttpConnection extends HttpConnection public Connection handle() throws IOException { Connection connection = this; - boolean some_progress=false; - boolean progress=true; - + boolean some_progress=false; + boolean progress=true; + // Loop while more in buffer try { setCurrentConnection(this); boolean more_in_buffer =false; - + while (_endp.isOpen() && (more_in_buffer || progress) && connection==this) { progress=false; try { - + // Handle resumed request if (_request._async.isAsync() && !_request._async.isComplete()) handleRequest(); - + // else Parse more input else if (!_parser.isComplete() && _parser.parseAvailable()>0) progress=true; @@ -55,11 +54,11 @@ public class AsyncHttpConnection extends HttpConnection // Generate more output if (_generator.isCommitted() && !_generator.isComplete() && _generator.flushBuffer()>0) progress=true; - + // Flush output from buffering endpoint if (_endp.isBufferingOutput()) _endp.flush(); - + // Special case close handling. // If we were dispatched and have made no progress, but io is shutdown, then close if (!progress && !some_progress && (_endp.isInputShutdown()||_endp.isOutputShutdown())) @@ -87,7 +86,7 @@ public class AsyncHttpConnection extends HttpConnection _endp.close(); reset(true); } - + // else Is this request/response round complete? else if (_parser.isComplete() && _generator.isComplete() && !_endp.isBufferingOutput()) { @@ -102,9 +101,9 @@ public class AsyncHttpConnection extends HttpConnection connection=switched; } } - + // Reset the parser/generator - // keep the buffers as we will cycle + // keep the buffers as we will cycle progress=true; reset(false); more_in_buffer = _parser.isMoreInBuffer() || _endp.isBufferingInput(); @@ -118,7 +117,7 @@ public class AsyncHttpConnection extends HttpConnection } else more_in_buffer = _parser.isMoreInBuffer() || _endp.isBufferingInput(); - + some_progress|=progress|((SelectChannelEndPoint)_endp).isProgressing(); } } @@ -132,19 +131,23 @@ public class AsyncHttpConnection extends HttpConnection // Check if we are write blocked if (_generator.isCommitted() && !_generator.isComplete() && _endp.isOpen() && !_endp.isOutputShutdown()) ((AsyncEndPoint)_endp).scheduleWrite(); // TODO. This should not be required - - if (!some_progress) - { - _total_no_progress++; - if (NO_PROGRESS_INFO>0 && _total_no_progress%NO_PROGRESS_INFO==0 && (NO_PROGRESS_CLOSE<=0 || _total_no_progress< NO_PROGRESS_CLOSE)) + if (some_progress) + { + _total_no_progress=0; + } + else + { + int totalNoProgress=++_total_no_progress; + + if (NO_PROGRESS_INFO>0 && totalNoProgress==NO_PROGRESS_INFO && (NO_PROGRESS_CLOSE<=0 || totalNoProgress0 && _total_no_progress==NO_PROGRESS_CLOSE) + + if (NO_PROGRESS_CLOSE>0 && totalNoProgress==NO_PROGRESS_CLOSE) { - LOG.warn("Closing EndPoint making no progress: "+_total_no_progress+" "+_endp); + LOG.warn("Closing EndPoint making no progress: {} {}", totalNoProgress, _endp); if (_endp instanceof SelectChannelEndPoint) { System.err.println(((SelectChannelEndPoint)_endp).getSelectManager().dump());