This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 63220eadcfc [improve][broker] Add idle timeout support for http
(#25224)
63220eadcfc is described below
commit 63220eadcfc11f43d4537327a3593603ee5be697
Author: Zixuan Liu <[email protected]>
AuthorDate: Fri Feb 6 23:02:58 2026 +0800
[improve][broker] Add idle timeout support for http (#25224)
---
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 261018ed683..61af4e86c5b 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 60af4d275be..2f2f52cbbde 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 d3037cdd44b..21c99f8196f 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
@@ -137,6 +137,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<>();
@@ -196,7 +197,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 622b1b034aa..7992cd20d11 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
@@ -124,6 +124,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 dbc7163ae65..3fc78e9f525 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()) {
@@ -181,7 +182,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);