From 9a0a1d952a44da0ff56d4ec286d8afee80478397 Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 16 Apr 2011 23:41:32 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50158 Ensure the asynchronous requests never timeout if the timeout is set to zero or less. Based on a patch provided by Chris. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1094088 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/AprEndpoint.java | 3 ++- java/org/apache/tomcat/util/net/JIoEndpoint.java | 3 ++- java/org/apache/tomcat/util/net/NioEndpoint.java | 17 ++++++++++------- java/org/apache/tomcat/util/net/SocketProperties.java | 4 ++-- webapps/docs/changelog.xml | 5 +++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index 53dd02449..194e18ce0 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -1024,7 +1024,8 @@ public class AprEndpoint extends AbstractEndpoint { SocketWrapper socket = sockets.next(); if (socket.async) { long access = socket.getLastAccess(); - if ((now-access)>socket.getTimeout()) { + if (socket.getTimeout() > 0 && + (now-access)>socket.getTimeout()) { processSocketAsync(socket,SocketStatus.TIMEOUT); } } diff --git a/java/org/apache/tomcat/util/net/JIoEndpoint.java b/java/org/apache/tomcat/util/net/JIoEndpoint.java index 3e97b4e44..4507430f6 100644 --- a/java/org/apache/tomcat/util/net/JIoEndpoint.java +++ b/java/org/apache/tomcat/util/net/JIoEndpoint.java @@ -150,7 +150,8 @@ public class JIoEndpoint extends AbstractEndpoint { while (sockets.hasNext()) { SocketWrapper socket = sockets.next(); long access = socket.getLastAccess(); - if ((now-access)>socket.getTimeout()) { + if (socket.getTimeout() > 0 && + (now-access)>socket.getTimeout()) { processSocketAsync(socket,SocketStatus.TIMEOUT); } } diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 0d751e75f..775b8bb4e 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1344,13 +1344,16 @@ public class NioEndpoint extends AbstractEndpoint { nextExpiration = (nextTime < nextExpiration)?nextTime:nextExpiration; } } else if (ka.isAsync() || ka.getComet()) { - long delta = now - ka.getLastAccess(); - long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout()); - boolean isTimedout = delta > timeout; - if (isTimedout) { - // Prevent subsequent timeouts if the timeout event takes a while to process - ka.access(Long.MAX_VALUE); - processSocket(ka.getChannel(), SocketStatus.TIMEOUT, true); + // Async requests with a timeout of 0 or less never timeout + if (!ka.isAsync() || ka.getTimeout() > 0) { + long delta = now - ka.getLastAccess(); + long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout()); + boolean isTimedout = delta > timeout; + if (isTimedout) { + // Prevent subsequent timeouts if the timeout event takes a while to process + ka.access(Long.MAX_VALUE); + processSocket(ka.getChannel(), SocketStatus.TIMEOUT, true); + } } }//end if }catch ( CancelledKeyException ckx ) { diff --git a/java/org/apache/tomcat/util/net/SocketProperties.java b/java/org/apache/tomcat/util/net/SocketProperties.java index 66a210132..b4363804f 100644 --- a/java/org/apache/tomcat/util/net/SocketProperties.java +++ b/java/org/apache/tomcat/util/net/SocketProperties.java @@ -173,8 +173,8 @@ public class SocketProperties { protected Integer performanceBandwidth = null; /** - * The minimum frequency of the timeout interval to avoid the - * poller going boinkers during high traffic + * The minimum frequency of the timeout interval to avoid excess load from + * the poller during high traffic */ protected long timeoutInterval = 1000; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6e98e2b94..585252319 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -82,6 +82,11 @@ 50957: Fix regression in HTTP BIO connector that triggered errors when processing pipe-lined requests. (markt) + + 50158: Ensure the asynchronous requests never timeout if the + timeout is set to zero or less. Based on a patch provided by Chris. + (markt) + -- 2.11.0