You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/09/29 18:49:20 UTC

(tomcat) 03/14: Add configurable timeout for HTTP connections used by the Manager Ant tasks

This is an automated email from the ASF dual-hosted git repository.

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

commit ab1757757a28cf2d964de4d53221bcb7c3c41a54
Author: opencode <re...@apache.org>
AuthorDate: Tue Sep 29 18:28:45 2026 +0200

    Add configurable timeout for HTTP connections used by the Manager Ant tasks
---
 .../apache/catalina/ant/AbstractCatalinaTask.java  | 34 ++++++++++++++++++++++
 java/org/apache/catalina/ant/DeployTask.java       |  4 +++
 2 files changed, 38 insertions(+)

diff --git a/java/org/apache/catalina/ant/AbstractCatalinaTask.java b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
index 5fc185117c..58d078de29 100644
--- a/java/org/apache/catalina/ant/AbstractCatalinaTask.java
+++ b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
@@ -96,6 +96,32 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
     }
 
 
+    /**
+     * The timeout, in seconds, used when establishing a connection to the server and when reading data from it. The
+     * default value of zero means no timeout, in which case an unresponsive server may cause the build to block
+     * indefinitely.
+     */
+    protected int timeout = 0;
+
+    /**
+     * Returns the connection and read timeout, in seconds.
+     *
+     * @return the timeout in seconds; zero means no timeout
+     */
+    public int getTimeout() {
+        return this.timeout;
+    }
+
+    /**
+     * Sets the connection and read timeout, in seconds.
+     *
+     * @param timeout the timeout in seconds; zero (the default) means no timeout
+     */
+    public void setTimeout(int timeout) {
+        this.timeout = timeout;
+    }
+
+
     /**
      * The URL of the <code>Manager</code> application to be used.
      */
@@ -227,6 +253,10 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
             hconn.setAllowUserInteraction(false);
             hconn.setDoInput(true);
             hconn.setUseCaches(false);
+            if (timeout > 0) {
+                hconn.setConnectTimeout(timeout * 1000);
+                hconn.setReadTimeout(timeout * 1000);
+            }
 
             // Set up authorization with our credentials
             Authenticator authenticator = new TaskAuthenticator(username, password);
@@ -346,6 +376,10 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
         hconn.setAllowUserInteraction(false);
         hconn.setDoInput(true);
         hconn.setUseCaches(false);
+        if (timeout > 0) {
+            hconn.setConnectTimeout(timeout * 1000);
+            hconn.setReadTimeout(timeout * 1000);
+        }
         hconn.setDoOutput(false);
         hconn.setAuthenticator(authenticator);
         hconn.setRequestMethod(Method.OPTIONS);
diff --git a/java/org/apache/catalina/ant/DeployTask.java b/java/org/apache/catalina/ant/DeployTask.java
index 9b26a31a7f..6595b20d9e 100644
--- a/java/org/apache/catalina/ant/DeployTask.java
+++ b/java/org/apache/catalina/ant/DeployTask.java
@@ -188,6 +188,10 @@ public class DeployTask extends AbstractCatalinaCommandTask {
                 try {
                     URI uri = new URI(war);
                     URLConnection conn = uri.toURL().openConnection();
+                    if (timeout > 0) {
+                        conn.setConnectTimeout(timeout * 1000);
+                        conn.setReadTimeout(timeout * 1000);
+                    }
                     contentLength = conn.getContentLengthLong();
                     stream = new BufferedInputStream(conn.getInputStream(), 1024);
                 } catch (IOException | URISyntaxException e) {


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org