(tomcat) 02/04: Allow any positive value for socket.unlockTimeout rather than >=2s

2024-04-19 Thread markt
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 
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 {
 
 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 {
 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)
   
+  
+Allow any positive value for socket.unlockTimeout. If a
+negative or zero value is 

(tomcat) 02/04: Allow any positive value for socket.unlockTimeout rather than >=2s

2024-04-19 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit b79a946cbc3fa55073c733dbf4a9ab1c5fdbd003
Author: Mark Thomas 
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 a46ee4ce9e..460e7543f5 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1129,12 +1129,8 @@ public abstract class AbstractEndpoint {
 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.
@@ -1142,7 +1138,7 @@ public abstract class AbstractEndpoint {
 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 8557463f7e..35c9d890c2 100644
--- a/java/org/apache/tomcat/util/net/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/net/LocalStrings.properties
@@ -139,6 +139,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 3a295c0937..53ebb4a103 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -153,6 +153,11 @@
 Align non-secure and secure writes with NIO and skip the write attempt
 when there are no bytes to be written. (markt)
   
+  
+Allow any