From 3f8b6017a0edd500ced05a628e9e0c380a0970c3 Mon Sep 17 00:00:00 2001 From: rishvv Date: Wed, 13 May 2026 17:16:02 -0600 Subject: [PATCH] fix(stepfunctions): honour TimeoutSeconds on Parallel state (#771) The Parallel state executor was using a hardcoded 60-second deadline per branch future instead of reading the optional TimeoutSeconds field from the state definition. When TimeoutSeconds is set, a single deadline is computed before collecting results so the limit applies across all branches rather than per-branch. When TimeoutSeconds is absent the futures are awaited without a deadline, matching the AWS behaviour of no timeout unless specified. --- .../services/stepfunctions/AslExecutor.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java index 7b28b63d15..0ab32e402c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java @@ -830,9 +830,26 @@ public class AslExecutor { futures.add(executor.submit(() -> executeBranch(startAt, branchStates, capturedInput, sm, topLevelQueryLanguage, context))); } + int timeoutSeconds = stateDef.path("TimeoutSeconds").asInt(0); + long deadlineNanos = timeoutSeconds > 0 + ? System.nanoTime() + TimeUnit.SECONDS.toNanos(timeoutSeconds) + : Long.MAX_VALUE; + ArrayNode results = objectMapper.createArrayNode(); for (Future future : futures) { - results.add(future.get(60, TimeUnit.SECONDS)); + long remainingNanos = deadlineNanos - System.nanoTime(); + if (remainingNanos <= 0) { + futures.forEach(f -> f.cancel(true)); + throw new FailStateException("States.Timeout", + "Parallel state timed out after " + timeoutSeconds + " seconds"); + } + try { + results.add(future.get(remainingNanos, TimeUnit.NANOSECONDS)); + } catch (java.util.concurrent.TimeoutException e) { + futures.forEach(f -> f.cancel(true)); + throw new FailStateException("States.Timeout", + "Parallel state timed out after " + timeoutSeconds + " seconds"); + } } if (jsonata) {