fix(lambda): use SO_REUSEADDR in stopReleasesPortSynchronously test (#991)

* 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
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-05-22 00:38:36 -05:00
1 parent 788ddf751f
commit c0ff98d0a8
1 file changed
+10 -1
@@ -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