fix(lambda): initialize ESM pollers at startup and fix worker-pool exhaustion in RuntimeApiServer (#543)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-04-21 07:24:27 -05:00
1 parent 9f231afc3b
commit c8057785eb
7 files changed
+52 -31

No files matched your search

@@ -7,6 +7,9 @@ import io.github.hectorvent.floci.lifecycle.inithook.InitializationHook;
import io.github.hectorvent.floci.lifecycle.inithook.InitializationHooksRunner;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
import io.github.hectorvent.floci.services.lambda.DynamoDbStreamsEventSourcePoller;
import io.github.hectorvent.floci.services.lambda.KinesisEventSourcePoller;
import io.github.hectorvent.floci.services.lambda.SqsEventSourcePoller;
import io.github.hectorvent.floci.services.rds.container.RdsContainerManager;
import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager;
import io.quarkus.runtime.ShutdownDelayInitiatedEvent;
@@ -39,6 +42,9 @@ class EmulatorLifecycleTest {
@Mock private RdsContainerManager rdsContainerManager;
@Mock private RdsProxyManager rdsProxyManager;
@Mock private InitializationHooksRunner initializationHooksRunner;
@Mock private SqsEventSourcePoller sqsPoller;
@Mock private KinesisEventSourcePoller kinesisPoller;
@Mock private DynamoDbStreamsEventSourcePoller dynamodbStreamsPoller;
private EmulatorLifecycle emulatorLifecycle;
@@ -47,7 +53,8 @@ class EmulatorLifecycleTest {
emulatorLifecycle = new EmulatorLifecycle(
storageFactory, serviceRegistry, config,
elastiCacheContainerManager, elastiCacheProxyManager,
rdsContainerManager, rdsProxyManager, initializationHooksRunner);
rdsContainerManager, rdsProxyManager, initializationHooksRunner,
sqsPoller, kinesisPoller, dynamodbStreamsPoller);
}
private void stubStorageConfig() {
@@ -78,30 +78,30 @@ class RuntimeApiServerTest {
@Test
@Timeout(45)
void nextEndpoint_doesNotReturn204AfterPollCycle() throws Exception {
void nextEndpoint_returns204OnTimeout_thenReturns200OnRepoll() throws Exception {
// AWS Runtime API contract: GET /next returns 204 when no invocation arrives within
// the poll window. The runtime re-polls and picks up the next queued invocation.
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:" + port + "/2018-06-01/runtime/invocation/next"))
.GET()
.build();
CompletableFuture<HttpResponse<String>> asyncResponse =
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());
Thread.sleep(33_000);
assertFalse(asyncResponse.isDone(),
"GET /next must NOT return (old bug: 204 after 30s single poll)");
// First poll: nothing queued — should return 204 after ~30 s.
HttpResponse<String> emptyResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(204, emptyResponse.statusCode(),
"GET /next should return 204 when the queue is empty after the poll timeout");
// Enqueue an invocation and re-poll — should be returned immediately.
PendingInvocation invocation = new PendingInvocation(
"req-delayed", "{\"after_poll_cycle\":true}".getBytes(),
"req-after-timeout", "{\"repoll\":true}".getBytes(),
System.currentTimeMillis() + 60_000,
"arn:aws:lambda:us-east-1:000000000000:function:test",
new CompletableFuture<>());
server.enqueue(invocation);
HttpResponse<String> response = asyncResponse.get(10, TimeUnit.SECONDS);
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode());
assertEquals("req-delayed",
assertEquals("req-after-timeout",
response.headers().firstValue("Lambda-Runtime-Aws-Request-Id").orElse(""));
}