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.
This commit is contained in:
rishvv authored and GitHub committed 2026-05-13 18:16:02 -05:00
1 parent 5d992a5d87
commit 3f8b6017a0
1 file changed
+18 -1
@@ -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<JsonNode> 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) {