From c3f0254803b9bdaf59656cd20058d05baa2f68f5 Mon Sep 17 00:00:00 2001 From: detailyang Date: Wed, 20 Nov 2024 06:05:20 +0800 Subject: [PATCH] fix calling cleanup function in Worker.run() to avoid race condition (#1455) --- minio/helpers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/minio/helpers.py b/minio/helpers.py index 2fb11ea04..50863bfeb 100644 --- a/minio/helpers.py +++ b/minio/helpers.py @@ -829,18 +829,19 @@ def run(self): if not task: self._tasks_queue.task_done() break + func, args, kargs, cleanup_func = task # No exception detected in any thread, # continue the execution. if self._exceptions_queue.empty(): - # Execute the task - func, args, kargs, cleanup_func = task try: result = func(*args, **kargs) self._results_queue.put(result) except Exception as ex: # pylint: disable=broad-except self._exceptions_queue.put(ex) - finally: - cleanup_func() + + # call cleanup i.e. Semaphore.release irrespective of task + # execution to avoid race condition. + cleanup_func() # Mark this task as done, whether an exception happened or not self._tasks_queue.task_done()