This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 3f9b18d7788300571178b6d3f95e96fdbd80504b 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 | 6 +----- 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, 25 insertions(+), 8 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java index 19edc2f514..b047a5490e 100644 --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java @@ -1183,13 +1183,9 @@ public abstract class AbstractEndpoint<S,U> { try (java.net.Socket s = new java.net.Socket()) { int stmo = 2 * 1000; - int utmo = 2 * 1000; if (getSocketProperties().getSoTimeout() > stmo) { stmo = getSocketProperties().getSoTimeout(); } - if (getSocketProperties().getUnlockTimeout() > utmo) { - utmo = getSocketProperties().getUnlockTimeout(); - } s.setSoTimeout(stmo); // 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 @@ -1198,7 +1194,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 (getDeferAccept()) { /* * In the case of a deferred accept / accept filters we need to diff --git a/java/org/apache/tomcat/util/net/LocalStrings.properties b/java/org/apache/tomcat/util/net/LocalStrings.properties index 0945510492..10b4fc1f47 100644 --- a/java/org/apache/tomcat/util/net/LocalStrings.properties +++ b/java/org/apache/tomcat/util/net/LocalStrings.properties @@ -161,6 +161,8 @@ socket.apr.write.error=Unexpected error [{0}] writing data to the APR/native soc 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 b08325a20c..d71f6bffb8 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 @@ -462,7 +469,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")); + } } void setObjectName(ObjectName oname) { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 8bb08ecb3c..c3f8e97f95 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -143,6 +143,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 253fed0314..c6beb0e130 100644 --- a/webapps/docs/config/http.xml +++ b/webapps/docs/config/http.xml @@ -843,8 +843,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