Skip to content

Commit

Permalink
fix calling cleanup function in Worker.run() to avoid race condition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
detailyang authored Nov 19, 2024
1 parent 3ead668 commit c3f0254
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions minio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit c3f0254

Please sign in to comment.