Skip to content

Commit c3f0254

Browse files
authored
fix calling cleanup function in Worker.run() to avoid race condition (minio#1455)
1 parent 3ead668 commit c3f0254

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

minio/helpers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,18 +829,19 @@ def run(self):
829829
if not task:
830830
self._tasks_queue.task_done()
831831
break
832+
func, args, kargs, cleanup_func = task
832833
# No exception detected in any thread,
833834
# continue the execution.
834835
if self._exceptions_queue.empty():
835-
# Execute the task
836-
func, args, kargs, cleanup_func = task
837836
try:
838837
result = func(*args, **kargs)
839838
self._results_queue.put(result)
840839
except Exception as ex: # pylint: disable=broad-except
841840
self._exceptions_queue.put(ex)
842-
finally:
843-
cleanup_func()
841+
842+
# call cleanup i.e. Semaphore.release irrespective of task
843+
# execution to avoid race condition.
844+
cleanup_func()
844845
# Mark this task as done, whether an exception happened or not
845846
self._tasks_queue.task_done()
846847

0 commit comments

Comments
 (0)