From ffdc6992682d2eeed58bb9fc9f579ea1321bcc5f Mon Sep 17 00:00:00 2001 From: Junwei Dai Date: Mon, 13 Jan 2025 13:17:02 -0800 Subject: [PATCH] Limit workflow timeout to non-negative Signed-off-by: Junwei Dai --- .../flowframework/util/WorkflowTimeoutUtility.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/util/WorkflowTimeoutUtility.java b/src/main/java/org/opensearch/flowframework/util/WorkflowTimeoutUtility.java index 7ecad2e1..341de98d 100644 --- a/src/main/java/org/opensearch/flowframework/util/WorkflowTimeoutUtility.java +++ b/src/main/java/org/opensearch/flowframework/util/WorkflowTimeoutUtility.java @@ -31,8 +31,7 @@ public class WorkflowTimeoutUtility { private static final Logger logger = LogManager.getLogger(WorkflowTimeoutUtility.class); - private static final TimeValue MAX_TIMEOUT_MILLIS = TimeValue.timeValueSeconds(300); - private static final TimeValue MIN_TIMEOUT_MILLIS = TimeValue.timeValueSeconds(1); + private static final TimeValue MIN_TIMEOUT_MILLIS = TimeValue.timeValueSeconds(0); /** * Schedules a timeout task for a workflow execution. @@ -53,8 +52,8 @@ public static ActionListener scheduleTimeoutHandler( long timeout, AtomicBoolean isResponseSent ) { - long adjustedTimeout = Math.min(timeout, MAX_TIMEOUT_MILLIS.millis()); - adjustedTimeout = Math.max(adjustedTimeout, MIN_TIMEOUT_MILLIS.millis()); + // Ensure timeout is within the valid range (non-negative) + long adjustedTimeout = Math.max(timeout, MIN_TIMEOUT_MILLIS.millis()); Scheduler.ScheduledCancellable scheduledCancellable = threadPool.schedule( new WorkflowTimeoutListener(client, workflowId, listener, isResponseSent), TimeValue.timeValueMillis(adjustedTimeout),