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

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


The following commit(s) were added to refs/heads/main by this push:
     new 0086f9a908 Follow on to "Keep existing proxy connections in 
TcpSender.init..."
0086f9a908 is described below

commit 0086f9a908fc8f7c755353d3836dab69d2d0cbdd
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Oct 1 20:49:18 2026 +0100

    Follow on to "Keep existing proxy connections in TcpSender.init..."
    
    - Handle the case where the failure is due to a DNS change
---
 .../catalina/ha/backend/LocalStrings.properties    |  1 +
 java/org/apache/catalina/ha/backend/Proxy.java     |  6 ++++++
 java/org/apache/catalina/ha/backend/TcpSender.java | 22 +++++++++++++++++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/ha/backend/LocalStrings.properties 
b/java/org/apache/catalina/ha/backend/LocalStrings.properties
index 79b029d13a..32007f9f8a 100644
--- a/java/org/apache/catalina/ha/backend/LocalStrings.properties
+++ b/java/org/apache/catalina/ha/backend/LocalStrings.properties
@@ -33,5 +33,6 @@ tcpSender.invalidProxyList=Invalid proxy list
 tcpSender.notInitialized=Not initialized
 tcpSender.readError=Error reading response content
 tcpSender.responseError=Unable to read response from proxy
+tcpSender.resolveFailed=Unable to re-resolve proxy [{0}], using the previously 
resolved address
 tcpSender.responseErrorCode=Response error with code [{0}]
 tcpSender.sendFailed=Unable to send collected load information to proxy
diff --git a/java/org/apache/catalina/ha/backend/Proxy.java 
b/java/org/apache/catalina/ha/backend/Proxy.java
index 1843f464cf..d16bfe7050 100644
--- a/java/org/apache/catalina/ha/backend/Proxy.java
+++ b/java/org/apache/catalina/ha/backend/Proxy.java
@@ -23,6 +23,12 @@ import java.net.InetAddress;
  */
 public class Proxy {
 
+    /**
+     * The host name or address of the front-end proxy server as configured. 
Retained so that the address can be
+     * re-resolved if the proxy's DNS entry changes.
+     */
+    public String host = null;
+
     /**
      * The IP address of the front-end proxy server.
      */
diff --git a/java/org/apache/catalina/ha/backend/TcpSender.java 
b/java/org/apache/catalina/ha/backend/TcpSender.java
index 4098279516..1597090e18 100644
--- a/java/org/apache/catalina/ha/backend/TcpSender.java
+++ b/java/org/apache/catalina/ha/backend/TcpSender.java
@@ -116,7 +116,8 @@ public class TcpSender implements Sender {
             proxies[i] = new Proxy();
             try {
                 proxies[i].port = Integer.parseInt(token.substring(pos + 1));
-                proxies[i].address = InetAddress.getByName(token.substring(0, 
pos));
+                proxies[i].host = token.substring(0, pos);
+                proxies[i].address = InetAddress.getByName(proxies[i].host);
             } catch (Exception e) {
                 throw new 
Exception(sm.getString("tcpSender.invalidProxyList"));
             }
@@ -140,6 +141,8 @@ public class TcpSender implements Sender {
         for (int i = 0; i < connections.length; i++) {
             if (connections[i] == null) {
                 try {
+                    // Pick up any DNS change since this proxy was last 
resolved
+                    refreshProxyAddress(i);
                     connections[i] = new Socket();
                     // Never block the periodic event thread indefinitely
                     connections[i].setSoTimeout(READ_TIMEOUT);
@@ -306,4 +309,21 @@ public class TcpSender implements Sender {
         }
         connections[i] = null;
     }
+
+
+    /**
+     * Re-resolve the address of the given proxy. If resolution fails the 
previously resolved address is kept so a
+     * transient DNS failure does not stop heartbeats to a proxy that is still 
reachable.
+     *
+     * @param i The index of the proxy
+     */
+    private void refreshProxyAddress(int i) {
+        try {
+            proxies[i].address = InetAddress.getByName(proxies[i].host);
+        } catch (IOException e) {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("tcpSender.resolveFailed", 
proxies[i].host), e);
+            }
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to