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

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


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new 6421425e2d5 [improve][broker] Add idle timeout support for http 
(#25224)
6421425e2d5 is described below

commit 6421425e2d57ce598ca5d0456457afc14f7348af
Author: Zixuan Liu <[email protected]>
AuthorDate: Fri Feb 6 23:02:58 2026 +0800

    [improve][broker] Add idle timeout support for http (#25224)
    
    (cherry picked from commit 63220eadcfc11f43d4537327a3593603ee5be697)
---
 conf/broker.conf                                          |  3 +++
 conf/proxy.conf                                           |  6 ++++++
 conf/standalone.conf                                      |  3 +++
 .../org/apache/pulsar/broker/ServiceConfiguration.java    |  6 ++++++
 .../java/org/apache/pulsar/broker/web/WebService.java     |  6 +++++-
 .../org/apache/pulsar/proxy/server/AdminProxyHandler.java |  2 ++
 .../apache/pulsar/proxy/server/ProxyConfiguration.java    | 15 +++++++++++++++
 .../java/org/apache/pulsar/proxy/server/WebServer.java    |  6 +++++-
 8 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/conf/broker.conf b/conf/broker.conf
index f71c3b197ad..b2e74569f14 100644
--- a/conf/broker.conf
+++ b/conf/broker.conf
@@ -1073,6 +1073,9 @@ httpServerThreadPoolQueueSize=8192
 # Capacity for accept queue in the HTTP server
 httpServerAcceptQueueSize=8192
 
+# Idle timeout for HTTP server connections in milliseconds
+httpServerIdleTimeout=30000
+
 # Maximum number of inbound http connections. (0 to disable limiting)
 maxHttpServerConnections=2048
 
diff --git a/conf/proxy.conf b/conf/proxy.conf
index 6cfe8213fab..310d6131251 100644
--- a/conf/proxy.conf
+++ b/conf/proxy.conf
@@ -322,6 +322,9 @@ httpServerThreadPoolQueueSize=8192
 # Capacity for accept queue in the HTTP server
 httpServerAcceptQueueSize=8192
 
+#Idle timeout for HTTP server connections in milliseconds
+httpServerIdleTimeout=30000
+
 # Maximum number of inbound http connections. (0 to disable limiting)
 maxHttpServerConnections=2048
 
@@ -333,6 +336,9 @@ maxConcurrentHttpRequests=1024
 # denial of service attacks.
 httpMaxRequestHeaderSize = 8192
 
+# The idle timeout value for HTTP proxy is in millisecond
+httpProxyIdleTimeout=30000
+
 ## Configure the datasource of basic authenticate, supports the file and 
Base64 format.
 # file:
 # basicAuthConf=/path/my/.htpasswd
diff --git a/conf/standalone.conf b/conf/standalone.conf
index b63caa1d9ec..571cc0fbbe8 100644
--- a/conf/standalone.conf
+++ b/conf/standalone.conf
@@ -1495,3 +1495,6 @@ topicCompactionRetainNullKey=false
 # will create topic compaction service based on message eventTime.
 # By default compaction service is based on message publishing order.
 
compactionServiceFactoryClassName=org.apache.pulsar.compaction.PulsarCompactionServiceFactory
+
+# Idle timeout for HTTP server connections in milliseconds
+httpServerIdleTimeout=30000
diff --git 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
index ceabf062b3a..93670bb2377 100644
--- 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+++ 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
@@ -347,6 +347,12 @@ public class ServiceConfiguration implements 
PulsarConfiguration {
     )
     private int httpServerAcceptQueueSize = 8192;
 
+    @FieldContext(
+            category = CATEGORY_HTTP,
+            doc = "Idle timeout for HTTP server connections in milliseconds."
+    )
+    private int httpServerIdleTimeout = 30 * 1000;
+
     @FieldContext(category = CATEGORY_SERVER, doc = "Maximum number of inbound 
http connections. "
             + "(0 to disable limiting)")
     private int maxHttpServerConnections = 2048;
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
index 96e8a516a6c..7fa954948a8 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
@@ -134,6 +134,7 @@ public class WebService implements AutoCloseable {
             httpConfig.addCustomizer(new ForwardedRequestCustomizer());
         }
         
httpConfig.setRequestHeaderSize(pulsar.getConfig().getHttpMaxRequestHeaderSize());
+        
httpConfig.setIdleTimeout(pulsar.getConfig().getHttpServerIdleTimeout());
         HttpConnectionFactory httpConnectionFactory = new 
HttpConnectionFactory(httpConfig);
         if (port.isPresent()) {
             List<ConnectionFactory> connectionFactories = new ArrayList<>();
@@ -191,7 +192,10 @@ public class WebService implements AutoCloseable {
         }
 
         // Limit number of concurrent HTTP connections to avoid getting out of 
file descriptors
-        connectors.forEach(c -> 
c.setAcceptQueueSize(config.getHttpServerAcceptQueueSize()));
+        connectors.forEach(c -> {
+            c.setAcceptQueueSize(config.getHttpServerAcceptQueueSize());
+            c.setIdleTimeout(pulsar.getConfig().getHttpServerIdleTimeout());
+        });
         server.setConnectors(connectors.toArray(new 
ServerConnector[connectors.size()]));
 
         filterInitializer = new FilterInitializer(pulsar);
diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/AdminProxyHandler.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/AdminProxyHandler.java
index 090f2f4a384..e4a38d7a0be 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/AdminProxyHandler.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/AdminProxyHandler.java
@@ -126,6 +126,8 @@ class AdminProxyHandler extends ProxyServlet {
             protocolHandlers.put(new RedirectProtocolHandler(httpClient));
         }
 
+        httpClient.setIdleTimeout(config.getHttpProxyIdleTimeout());
+
         setTimeout(config.getHttpProxyTimeout());
     }
 
diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
index 9fd91a591cb..d55be358188 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
@@ -808,6 +808,14 @@ public class ProxyConfiguration implements 
PulsarConfiguration {
     )
     private int httpProxyTimeout = 5 * 60 * 1000;
 
+    @FieldContext(
+            minValue = 0,
+            category = CATEGORY_HTTP,
+            doc = "Http proxy idle timeout.\n\n"
+                    + "The idle timeout value for HTTP proxy is in 
millisecond."
+    )
+    private int httpProxyIdleTimeout = 30 * 1000;
+
     @FieldContext(
            minValue = 1,
            category = CATEGORY_HTTP,
@@ -832,6 +840,13 @@ public class ProxyConfiguration implements 
PulsarConfiguration {
     )
     private int httpServerAcceptQueueSize = 8192;
 
+    @FieldContext(
+            minValue = 0,
+            category = CATEGORY_HTTP,
+            doc = "Idle timeout for HTTP server connections in milliseconds."
+    )
+    private int httpServerIdleTimeout = 30 * 1000;
+
     @FieldContext(category = CATEGORY_SERVER, doc = "Maximum number of inbound 
http connections. "
             + "(0 to disable limiting)")
     private int maxHttpServerConnections = 2048;
diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
index 7591b8b54db..842b127dcfb 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
@@ -126,6 +126,7 @@ public class WebServer {
         }
         httpConfig.setOutputBufferSize(config.getHttpOutputBufferSize());
         httpConfig.setRequestHeaderSize(config.getHttpMaxRequestHeaderSize());
+        httpConfig.setIdleTimeout(config.getHttpServerIdleTimeout());
 
         HttpConnectionFactory httpConnectionFactory = new 
HttpConnectionFactory(httpConfig);
         if (config.getWebServicePort().isPresent()) {
@@ -179,7 +180,10 @@ public class WebServer {
         }
 
         // Limit number of concurrent HTTP connections to avoid getting out of 
file descriptors
-        connectors.stream().forEach(c -> 
c.setAcceptQueueSize(config.getHttpServerAcceptQueueSize()));
+        connectors.stream().forEach(c -> {
+            c.setAcceptQueueSize(config.getHttpServerAcceptQueueSize());
+            c.setIdleTimeout(config.getHttpServerIdleTimeout());
+        });
         server.setConnectors(connectors.toArray(new 
ServerConnector[connectors.size()]));
 
         filterInitializer = new FilterInitializer(config, 
authenticationService);

Reply via email to