From c0ff98d0a89c1aeb6541722b984eda680f21ee72 Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Fri, 22 May 2026 00:38:36 -0500 Subject: [PATCH] fix(lambda): use SO_REUSEADDR in stopReleasesPortSynchronously test (#991) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(lambda): use SO_REUSEADDR in stopReleasesPortSynchronously test The test was verifying that the port is released after stop() by binding a plain ServerSocket (SO_REUSEADDR=false). On Linux this fails intermittently with BindException when any TCP connection on that port is still in TIME_WAIT The fix binds with SO_REUSEADDR=true, which is exactly how Vert.x/Netty and any real server restart reclaims a port. This makes the test assert the correct invariant without being sensitive to TIME_WAIT state. Also adds a Linux-only reproducer test that confirms a plain bind (without SO_REUSEADDR) throws BindException after stopping a server with an active keep-alive connection, documenting the root cause of the flaky CI failure. No production code changes — RuntimeApiServer.stop() was correct all along. * fix: remove flaky reproduce test error --- .../services/lambda/runtime/RuntimeApiServerTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServerTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServerTest.java index 70d7a3b9b5..6a652980b2 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServerTest.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import java.io.IOException; +import java.net.BindException; +import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.URI; import java.net.http.HttpClient; @@ -19,9 +21,13 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; class RuntimeApiServerTest { @@ -227,7 +233,10 @@ class RuntimeApiServerTest { @Timeout(10) void stopReleasesPortSynchronously() throws Exception { server.stop().get(5, TimeUnit.SECONDS); - new ServerSocket(port).close(); + try (ServerSocket s = new ServerSocket()) { + s.setReuseAddress(true); + s.bind(new InetSocketAddress(port)); + } } @Test