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

lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit a2ba5b8ba2e4dd6103c4b1a5bfe15aafe46557a1
Author: Lari Hotari <[email protected]>
AuthorDate: Thu Jul 17 07:24:23 2025 +0300

    [fix][proxy] Fix default value of connectionMaxIdleSeconds in Pulsar Proxy 
(#24529)
    
    (cherry picked from commit a87d47710b5495ebdbcbb07f61798f9af697e552)
---
 .../pulsar/proxy/server/ProxyConnection.java       |  4 +--
 .../org/apache/pulsar/proxy/server/ProxyTest.java  | 30 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
index bc27a8ba4f5..354d145a954 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
@@ -725,6 +725,8 @@ public class ProxyConnection extends PulsarHandler {
         ProxyConfiguration proxyConfig = service.getConfiguration();
         initialConf.setServiceUrl(
                 proxyConfig.isTlsEnabledWithBroker() ? 
service.getServiceUrlTls() : service.getServiceUrl());
+        /** The proxy service does not need to automatically clean up idling 
connections, so set to false. **/
+        initialConf.setConnectionMaxIdleSeconds(-1);
 
         // Apply all arbitrary configuration. This must be called before 
setting any fields annotated as
         // @Secret on the ClientConfigurationData object because of the way 
they are serialized.
@@ -733,8 +735,6 @@ public class ProxyConnection extends PulsarHandler {
                 .filterAndMapProperties(proxyConfig.getProperties(), 
"brokerClient_");
         ClientConfigurationData clientConf = ConfigurationDataUtils
                 .loadData(overrides, initialConf, 
ClientConfigurationData.class);
-        /** The proxy service does not need to automatically clean up invalid 
connections, so set false. **/
-        initialConf.setConnectionMaxIdleSeconds(-1);
         clientConf.setAuthentication(this.getClientAuthentication());
         if (proxyConfig.isTlsEnabledWithBroker()) {
             clientConf.setUseTls(true);
diff --git 
a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java 
b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java
index 73fd93ee44f..c7965db505e 100644
--- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java
+++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java
@@ -41,6 +41,8 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import org.apache.avro.reflect.Nullable;
+import org.apache.commons.lang3.mutable.MutableBoolean;
+import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.pulsar.PulsarVersion;
 import org.apache.pulsar.broker.BrokerTestUtil;
 import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
@@ -177,6 +179,34 @@ public class ProxyTest extends MockedPulsarServiceBaseTest 
{
         }
     }
 
+    @Test
+    public void testProxyConnectionClientConfig() throws Exception {
+        @Cleanup
+        PulsarClient client = 
PulsarClient.builder().serviceUrl(proxyService.getServiceUrl())
+                .build();
+
+        @Cleanup
+        Producer<byte[]> producer = client.newProducer()
+                .topic("persistent://sample/test/local/producer-topic2")
+                .create();
+
+        MutableBoolean found = new MutableBoolean(false);
+        proxyService.getClientCnxs().forEach(proxyConnection -> {
+            if (proxyConnection.getConnectionPool() != null) {
+                try {
+                    found.setTrue();
+                    assertEquals(-1,
+                            
FieldUtils.readDeclaredField(proxyConnection.getConnectionPool(),
+                                    "connectionMaxIdleSeconds",
+                                    true));
+                } catch (IllegalAccessException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+        assertTrue(found.isTrue(), "No proxy connection found with 
connectionMaxIdleSeconds set to -1");
+    }
+
     @Test
     public void testProducerConsumer() throws Exception {
         @Cleanup

Reply via email to