This is an automated email from the ASF dual-hosted git repository. xyz pushed a commit to branch branch-4.0 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 405e51abb83a9969d046047061647d0e59252ae6 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 e1179be115a..4f89f4bc17e 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 @@ -734,6 +734,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. @@ -742,8 +744,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 f8331b1c442..64ea589e023 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; @@ -180,6 +182,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
