Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using multitask with dependent tasks that fail, rake will sometimes exit before all subprocesses have exited #414

Open
win93 opened this issue Feb 6, 2022 · 1 comment

Comments

@win93
Copy link

win93 commented Feb 6, 2022

This behavior can be seen with the following Rakefile, then running rake all:

fake_task_names = ('a'..'z').to_a

multitask all: fake_task_names

fake_task_names.each_with_index do |fake_task_name, i|
  task fake_task_name do
    sh "sleep #{i} && echo 'simulated failure' && false"
  end
end

I expect that rake would let any jobs in flight finish up before reporting failure. Instead it reports failure, but some of the "simulated failure" messages print after rake exits, which ends up printing over my shell prompt.

I dug through the code a little bit and was able to come up with this as a suggested fix:

--- /home/alexg/.gem/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb~       2022-02-06 12:28:46.800753532 -0600
+++ /home/alexg/.gem/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb        2022-02-06 12:28:11.989792288 -0600
@@ -119,15 +119,15 @@
     end
 
     # Run the given block with the thread startup and shutdown.
     def run_with_threads
       thread_pool.gather_history if options.job_stats == :history
 
       yield
-
+    ensure
       thread_pool.join
       if options.job_stats
         stats = thread_pool.statistics
         puts "Maximum active threads: #{stats[:max_active_threads]} + main"
         puts "Total threads in play:  #{stats[:total_threads_in_play]} + main"
       end
       ThreadHistoryDisplay.new(thread_pool.history).show if

This would make sure that we wait on threads in the thread pool, even if an exception was raised from FileUtils#create_shell_runner, for example.

Using rake: 13.0.6, ruby: ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]

@Mike117687

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants