From 97984203d09fbe1cabb5fb274a7c64db24452ebe Mon Sep 17 00:00:00 2001 From: jnbdz Date: Sat, 15 Aug 2026 19:35:31 -0400 Subject: [PATCH] Keep the NetClient referenced in tests that rely on the connection staying open Motivation: Http2Test#testSslHandshakeTimeout is listed in #6218 as failing in 4 out of 60 CI runs with an unsatisfied checkpoint. The test connects with an unreferenced NetClient and returns, then waits for the server to report the handshake timeout. A client that is no longer referenced is closed when it is garbage collected, so under memory pressure the connection is closed before the handshake timeout happens and the server never reports it. Forcing a garbage collection after the connect reproduces the CI failure every time. HttpConnectionEarlyResetTest#testExceptionCaught has the same pattern: it expects a connection reset two seconds after connecting, a client closed by the garbage collector closes the connection gracefully instead. Changes: Keep the NetClient in a field in both tests so that it stays referenced for the duration of the test. --- .../src/test/java/io/vertx/tests/http/Http2Test.java | 8 +++++++- .../io/vertx/tests/http/HttpConnectionEarlyResetTest.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java b/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java index 213a072c0d1..1bad37fe595 100644 --- a/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java +++ b/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java @@ -19,6 +19,7 @@ import io.vertx.core.buffer.Buffer; import io.vertx.core.http.*; import io.vertx.core.net.JdkSSLEngineOptions; +import io.vertx.core.net.NetClient; import io.vertx.core.net.NetSocket; import io.vertx.core.net.OpenSSLEngineOptions; import io.vertx.core.net.SSLEngineOptions; @@ -53,6 +54,8 @@ */ public class Http2Test extends HttpTest { + private NetClient netClient; + public Http2Test() { this(false); } @@ -735,7 +738,10 @@ public void testSslHandshakeTimeout(Checkpoint checkpoint) throws Exception { } }); startServer(); - NetSocket so = vertx.createNetClient().connect(config.port(), config.host()).await(); + // Keep a reference to the client: an unreferenced client is closed when it is garbage collected, which + // would close the connection before the handshake timeout happens + netClient = vertx.createNetClient(); + netClient.connect(config.port(), config.host()).await(); } @Test diff --git a/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java b/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java index b06c1c186be..73fdea0342b 100644 --- a/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java @@ -14,6 +14,7 @@ import io.vertx.core.Context; import io.vertx.core.Vertx; import io.vertx.core.http.HttpServer; +import io.vertx.core.net.NetClient; import io.vertx.core.net.NetClientOptions; import io.vertx.test.core.VertxTestBase; import io.vertx.test.http.HttpTestBase; @@ -34,6 +35,7 @@ public class HttpConnectionEarlyResetTest extends VertxTestBase { private HttpServer httpServer; + private NetClient client; private AtomicReference caught = new AtomicReference<>(); private CountDownLatch resetLatch = new CountDownLatch(1); @@ -57,7 +59,10 @@ public void setUp() throws Exception { @Test public void testExceptionCaught() throws Exception { - vertx.createNetClient(new NetClientOptions().setSoLinger(0)).connect(HttpTestBase.DEFAULT_HTTP_PORT, "localhost").onComplete(onSuccess(socket -> { + // Keep a reference to the client: an unreferenced client is closed when it is garbage collected, which + // would close the connection gracefully before the reset + client = vertx.createNetClient(new NetClientOptions().setSoLinger(0)); + client.connect(HttpTestBase.DEFAULT_HTTP_PORT, "localhost").onComplete(onSuccess(socket -> { vertx.setTimer(2000, id -> { socket.close(); });