This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new eedf5dc5c7 Follow on to "Keep existing proxy connections in
TcpSender.init..."
eedf5dc5c7 is described below
commit eedf5dc5c725c0946bc9d518884bb4177b683e6b
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 50a691cf01..40bfde6419 100644
--- a/java/org/apache/catalina/ha/backend/LocalStrings.properties
+++ b/java/org/apache/catalina/ha/backend/LocalStrings.properties
@@ -36,5 +36,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]