From e0a330756368f66a8b7986f6d4ea7fcbbf76b145 Mon Sep 17 00:00:00 2001 From: takatost Date: Fri, 20 Sep 2024 19:47:25 +0800 Subject: [PATCH] fix(workflow): "Max submit count reached" error occurred when executing workflow as tool in iteration (#8595) --- api/core/workflow/graph_engine/graph_engine.py | 10 +++++++--- api/core/workflow/nodes/iteration/iteration_node.py | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/core/workflow/graph_engine/graph_engine.py b/api/core/workflow/graph_engine/graph_engine.py index 57e4f716fd..8342dbd13d 100644 --- a/api/core/workflow/graph_engine/graph_engine.py +++ b/api/core/workflow/graph_engine/graph_engine.py @@ -180,16 +180,20 @@ class GraphEngine: # trigger graph run success event yield GraphRunSucceededEvent(outputs=self.graph_runtime_state.outputs) + self._release_thread() except GraphRunFailedError as e: yield GraphRunFailedEvent(error=e.error) + self._release_thread() return except Exception as e: logger.exception("Unknown Error when graph running") yield GraphRunFailedEvent(error=str(e)) + self._release_thread() raise e - finally: - if self.is_main_thread_pool and self.thread_pool_id in GraphEngine.workflow_thread_pool_mapping: - del GraphEngine.workflow_thread_pool_mapping[self.thread_pool_id] + + def _release_thread(self): + if self.is_main_thread_pool and self.thread_pool_id in GraphEngine.workflow_thread_pool_mapping: + del GraphEngine.workflow_thread_pool_mapping[self.thread_pool_id] def _run( self, diff --git a/api/core/workflow/nodes/iteration/iteration_node.py b/api/core/workflow/nodes/iteration/iteration_node.py index 6f20745daf..01bb4e9076 100644 --- a/api/core/workflow/nodes/iteration/iteration_node.py +++ b/api/core/workflow/nodes/iteration/iteration_node.py @@ -89,6 +89,7 @@ class IterationNode(BaseNode): variable_pool=variable_pool, max_execution_steps=dify_config.WORKFLOW_MAX_EXECUTION_STEPS, max_execution_time=dify_config.WORKFLOW_MAX_EXECUTION_TIME, + thread_pool_id=self.thread_pool_id, ) start_at = datetime.now(timezone.utc).replace(tzinfo=None)