From f72dd9cb503e837a39d2dfd9ca34b7a28a9cb22d Mon Sep 17 00:00:00 2001 From: Jihun Kim Date: Tue, 23 Jun 2026 22:02:09 +0900 Subject: [PATCH] Allow zero HTTP/2 keep-alive timeout Motivation: Http2ClientConfig#setKeepAliveTimeout(Duration.ZERO) throws, although zero and null are documented as no timeout. HTTP/1 and HTTP/3 client configs already accept zero. Changes: Allow zero for HTTP/2 keep-alive timeout and add a regression test. Signed-off-by: Jihun Kim --- .../java/io/vertx/core/http/Http2ClientConfig.java | 2 +- .../java/io/vertx/tests/http/HttpClientConfigTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vertx-core/src/main/java/io/vertx/core/http/Http2ClientConfig.java b/vertx-core/src/main/java/io/vertx/core/http/Http2ClientConfig.java index 4c00d522339..31668c19382 100644 --- a/vertx-core/src/main/java/io/vertx/core/http/Http2ClientConfig.java +++ b/vertx-core/src/main/java/io/vertx/core/http/Http2ClientConfig.java @@ -119,7 +119,7 @@ public Duration getKeepAliveTimeout() { * @return a reference to this, so the API can be used fluently */ public Http2ClientConfig setKeepAliveTimeout(Duration keepAliveTimeout) { - if (keepAliveTimeout != null && (keepAliveTimeout.isNegative() || keepAliveTimeout.isZero())) { + if (keepAliveTimeout != null && (keepAliveTimeout.isNegative())) { throw new IllegalArgumentException("HTTP/2 keepAliveTimeout must be >= 0"); } this.keepAliveTimeout = keepAliveTimeout; diff --git a/vertx-core/src/test/java/io/vertx/tests/http/HttpClientConfigTest.java b/vertx-core/src/test/java/io/vertx/tests/http/HttpClientConfigTest.java index 0544b27c48e..3efda1a4e68 100644 --- a/vertx-core/src/test/java/io/vertx/tests/http/HttpClientConfigTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/http/HttpClientConfigTest.java @@ -12,8 +12,10 @@ import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpClientConfig; +import io.vertx.core.http.Http2ClientConfig; import org.junit.Test; +import java.time.Duration; import java.util.List; import static io.vertx.core.http.HttpVersion.*; @@ -60,4 +62,12 @@ public void testFromHttp1_0Options() { assertFalse(config.isSsl()); assertEquals(List.of(HTTP_1_0), config.getVersions()); } + + @Test + public void testHttp2KeepAliveTimeoutValidation() { + Http2ClientConfig config = new Http2ClientConfig(); + assertSame(config, config.setKeepAliveTimeout(Duration.ZERO)); + assertEquals(Duration.ZERO, config.getKeepAliveTimeout()); + assertThrows(IllegalArgumentException.class, () -> config.setKeepAliveTimeout(Duration.ofMillis(-1))); + } }