From b68ee4142ff179d4b468902054ac907642448f97 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 7 Sep 2024 14:45:30 +0200 Subject: [PATCH] Ensure thread-pool shutdown. --- Library/Homebrew/cmd/fetch.rb | 4 +++- Library/Homebrew/download_queue.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 670a425093..6bd826c48d 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -301,6 +301,8 @@ module Homebrew # FIXME: Implement cancellation of running downloads. end + download_queue.cancel + if previous_pending_line_count.positive? $stdout.print Tty.move_cursor_down(previous_pending_line_count - 1) $stdout.flush @@ -314,7 +316,7 @@ module Homebrew $stdout.flush end end - + ensure download_queue.shutdown end diff --git a/Library/Homebrew/download_queue.rb b/Library/Homebrew/download_queue.rb index 7fac89fa20..e591c3f2ae 100644 --- a/Library/Homebrew/download_queue.rb +++ b/Library/Homebrew/download_queue.rb @@ -28,9 +28,18 @@ module Homebrew # rubocop:enable Lint/ShadowingOuterLocalVariable end + sig { void } + def cancel + # FIXME: Implement graceful cancellaction of running downloads based on + # https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Cancellation.html + # instead of killing the whole thread pool. + pool.kill + end + sig { void } def shutdown pool.shutdown + pool.wait_for_termination end end end