This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 2bbee3883dd40f3612fc2620fc58b2f43ee5debd Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Apr 19 17:49:26 2024 +0100 Allow any positive value for socket.unlockTimeout rather than >=2s Implement limit in setter so it always applies. --- java/org/apache/tomcat/util/net/AbstractEndpoint.java | 8 ++------ java/org/apache/tomcat/util/net/LocalStrings.properties | 2 ++ java/org/apache/tomcat/util/net/SocketProperties.java | 13 ++++++++++++- webapps/docs/changelog.xml | 5 +++++ webapps/docs/config/http.xml | 7 +++++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java index 1e0f3bf28b..c3a5ee523d 100644 --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java @@ -1285,12 +1285,8 @@ public abstract class AbstractEndpoint<S,U> { unlockAddress = getUnlockAddress(localAddress); try (java.net.Socket s = new java.net.Socket()) { - int utmo = 2 * 1000; - if (getSocketProperties().getUnlockTimeout() > utmo) { - utmo = getSocketProperties().getUnlockTimeout(); - } // Never going to read from this socket so the timeout doesn't matter. Use the unlock timeout. - s.setSoTimeout(utmo); + s.setSoTimeout(getSocketProperties().getUnlockTimeout()); // Newer MacOS versions (e.g. Ventura 13.2) appear to linger for ~1s on close when linger is disabled. // That causes delays when running the unit tests. Explicitly enabling linger but with a timeout of // zero seconds seems to fix the issue. @@ -1298,7 +1294,7 @@ public abstract class AbstractEndpoint<S,U> { if (getLog().isTraceEnabled()) { getLog().trace("About to unlock socket for:" + unlockAddress); } - s.connect(unlockAddress,utmo); + s.connect(unlockAddress, getSocketProperties().getUnlockTimeout()); if (getLog().isTraceEnabled()) { getLog().trace("Socket unlock completed for:" + unlockAddress); } diff --git a/java/org/apache/tomcat/util/net/LocalStrings.properties b/java/org/apache/tomcat/util/net/LocalStrings.properties index 20460c9326..f10dfafc03 100644 --- a/java/org/apache/tomcat/util/net/LocalStrings.properties +++ b/java/org/apache/tomcat/util/net/LocalStrings.properties @@ -140,6 +140,8 @@ sniExtractor.tooEarly=It is illegal to call this method before the client hello socket.closed=The socket associated with this connection has been closed. socket.sslreneg=Exception re-negotiating SSL connection +socketProperties.negativeUnlockTimeout=The negative value for unlockTimeout has been ignored + socketWrapper.readTimeout=Read timeout socketWrapper.writeTimeout=Write timeout diff --git a/java/org/apache/tomcat/util/net/SocketProperties.java b/java/org/apache/tomcat/util/net/SocketProperties.java index b91d54f0e2..10b9fd765f 100644 --- a/java/org/apache/tomcat/util/net/SocketProperties.java +++ b/java/org/apache/tomcat/util/net/SocketProperties.java @@ -26,6 +26,10 @@ import java.nio.channels.AsynchronousSocketChannel; import javax.management.ObjectName; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.res.StringManager; + /** * Properties that can be set in the <Connector> element * in server.xml. All properties are prefixed with "socket." @@ -33,6 +37,9 @@ import javax.management.ObjectName; */ public class SocketProperties { + private static final Log log = LogFactory.getLog(SocketProperties.class); + private static final StringManager sm = StringManager.getManager(SocketProperties.class); + /** * Enable/disable socket processor cache, this bounded cache stores * SocketProcessor objects to reduce GC @@ -451,7 +458,11 @@ public class SocketProperties { } public void setUnlockTimeout(int unlockTimeout) { - this.unlockTimeout = unlockTimeout; + if (unlockTimeout > 0) { + this.unlockTimeout = unlockTimeout; + } else { + log.warn(sm.getString("socketProperties.negativeUnlockTimeout")); + } } /** diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index f6eacba634..6cc139f23a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -148,6 +148,11 @@ Align non-secure and secure writes with NIO and skip the write attempt when there are no bytes to be written. (markt) </fix> + <fix> + Allow any positive value for <code>socket.unlockTimeout</code>. If a + negative or zero value is configured, the default of <code>250ms</code> + will be used. (mark) + </fix> </changelog> </subsection> <subsection name="Other"> diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml index c0636f5559..d8ccdf6a2c 100644 --- a/webapps/docs/config/http.xml +++ b/webapps/docs/config/http.xml @@ -798,8 +798,11 @@ be used for all three.</p> </attribute> <attribute name="socket.unlockTimeout" required="false"> - <p>(int) The timeout for a socket unlock. When a connector is stopped, it will try to release the acceptor thread by opening a connector to itself. - The default value is <code>250</code> and the value is in milliseconds</p> + <p>(int) The timeout for a socket unlock. When a connector is stopped, + it will try to release the acceptor thread by opening a connector to + itself. The default value is <code>250</code> and the value is in + milliseconds. This vaoue must be positive. Negative or zero values will + be ignored.</p> </attribute> </attributes> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org