mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
test(lambda): wait for the parked poll instead of sleeping in extension stop race (#2131)
extensionRegister_racedAgainstStop_eventuallyDeliversShutdown slept 5ms to let the extension's /event/next poll connect and park before racing stop() against it, then asserted SHUTDOWN came back on that request. The sleep asserts the poll has parked without checking. On a loaded machine it expires first, so stop() closes the listening socket while the request is still in flight: the poll never reaches the handler, stop()'s SHUTDOWN fan-out finds no waiting context to hand the event to, and the client sees the connection die instead of the SHUTDOWN the test is about. That surfaces as an EOFException (connection accepted, then torn down) or a ConnectException (lost the race before the connect even landed) out of asyncNext.get(), and it failed CI this way once in 8325 tests. Replace the sleep with awaitExtensionParked(), polling a new package-private RuntimeApiServer.isExtensionParked() until the poll has provably parked, so the race the test sets up is the one it means to test. isExtensionParked reads under the same lock as the rest of the extension state, per the class's documented locking discipline; RegisteredExtension.hasWaitingContext() peeks without consuming, unlike takeWaitingContext(). The test still fails if the "poll pendingEvents before checking stopped" fix in the /event/next handler is reverted, so this removes the flake without weakening the regression it covers. Verified by breaking that fix and watching this test go red, and by reproducing the original failure under CPU saturation before and after the change.
This commit is contained in:
3 files changed
+56
-3
No files matched your search
+9
@@ -49,6 +49,15 @@ public class RegisteredExtension {
|
||||
waitingContext = ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a poll is currently parked, without consuming it — unlike
|
||||
* {@link #takeWaitingContext()}, which clears the context as it hands it over. Called under the
|
||||
* owning server's lock, like the rest of this class.
|
||||
*/
|
||||
public boolean hasWaitingContext() {
|
||||
return waitingContext != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records that this extension has issued its first {@code /extension/event/next}, which is
|
||||
* what AWS treats as the extension being init-ready (registering alone only obtains an
|
||||
|
||||
+19
@@ -218,6 +218,25 @@ public class RuntimeApiServer {
|
||||
return latch.await(timeoutMs, java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when this extension is currently parked on {@code /extension/event/next} — its request
|
||||
* reached the handler and was stored as the waiting context rather than answered immediately.
|
||||
*
|
||||
* <p>Package-private and used only by tests that race {@link #stop()} against a poll already in
|
||||
* flight. Such a test cannot use a sleep to decide the poll has landed: the request parking is
|
||||
* what makes {@code stop()}'s SHUTDOWN fan-out see a waiting context instead of queueing the
|
||||
* event for a connection that is about to be torn down, and on a loaded machine an arbitrary
|
||||
* sleep expires before that happens. Polling this instead makes the wait condition-based.
|
||||
*
|
||||
* <p>Read under {@code lock}, per the locking discipline in the class doc.
|
||||
*/
|
||||
boolean isExtensionParked(String identifier) {
|
||||
synchronized (lock) {
|
||||
RegisteredExtension extension = extensions.get(identifier);
|
||||
return extension != null && extension.hasWaitingContext();
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> start() {
|
||||
CompletableFuture<Void> started = new CompletableFuture<>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user