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.
This commit is contained in:
Alex Banna authored and GitHub committed 2026-08-08 22:34:26 -05:00
1 parent cb06a73b78
commit 41d2a3cd19
1 file changed
+8 -5
@@ -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<String> response = asyncNext.get(5, TimeUnit.SECONDS);