diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/model/RegisteredExtension.java b/src/main/java/io/github/hectorvent/floci/services/lambda/model/RegisteredExtension.java index 6eb5feda09..526f02f997 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/model/RegisteredExtension.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/model/RegisteredExtension.java @@ -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 diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java b/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java index 8dd861a27d..73156e8511 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java @@ -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. + * + *
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. + * + *
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