From 41d2a3cd196fbc036650ba2c6cc06255c56d7730 Mon Sep 17 00:00:00 2001 From: Alex Banna Date: Sat, 8 Aug 2026 22:34:26 -0500 Subject: [PATCH] test(lambda): wait for the parked poll in the extension shutdown stop race (#2141) extensionShutdown_racedAgainstStop_isNeverOrphaned still raced stop() against a Thread.sleep(5), the pattern #2131 replaced in its sibling extensionRegister_racedAgainstStop_eventuallyDeliversShutdown but left in place here. A fixed sleep only assumes the poll parked; on a loaded runner it expires first, stop() closes the listening socket while the request is still in flight, and the client sees EOFException instead of the SHUTDOWN the test is asserting. Reuse the awaitExtensionParked helper #2131 already added, so the race is set up against a poll that has provably landed. Reproduced by running the class under 'docker run --cpus=1' to emulate a contended runner: fails on the unpatched tree, 45/45 green on the patched one across repeated runs. Unconstrained it passes either way, which is why it only ever showed up in CI. --- .../lambda/runtime/RuntimeApiServerTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 14144ae6ab..8cb210c951 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 @@ -1043,11 +1043,14 @@ class RuntimeApiServerTest { .GET().build(), HttpResponse.BodyHandlers.ofString()); - // Give the request just enough time to actually connect and park server-side - // (a few ms is plenty on localhost) before racing stop() against it — without - // this, stop() can close the listening socket before the connection is even - // established, which isn't the race we're testing. - Thread.sleep(5); + // Wait for the poll to actually park before racing stop() against it. A fixed + // sleep only *assumes* it parked: on a loaded machine the sleep expires first, + // stop() closes the listening socket while the request is still in flight, and + // the client sees the connection die (EOFException) rather than the SHUTDOWN + // this test is about. Same reasoning as + // extensionRegister_racedAgainstStop_eventuallyDeliversShutdown. + assertTrue(awaitExtensionParked(freshServer, extensionId, 5000), + "extension never parked on /event/next; the stop() race was never set up"); freshServer.stop(); HttpResponse response = asyncNext.get(5, TimeUnit.SECONDS);