brandonhilkert / sucker_punch

Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
MIT License
2.65k stars 114 forks source link

Shutdown too early when processing with multiple workers #196

Closed nulian closed 7 years ago

nulian commented 7 years ago

When multiple workers are processing it could finish up before the timeout timer. The reason is because 1 worker can handle the latch.count_down while the other one is still processing.

brandonhilkert commented 7 years ago

Hi there! Thanks for the report. I'm not sure I'm totally clear on the what you're describing. Do you have code to describe the scenario? Thanks!

nulian commented 7 years ago

If you shoot in like 10 jobs that take 1 sec a piece and the shutdown_timeout == 15. And immediately after the jobs got added the servers gets a shutdown command like using ctrl + c. The final job won't succeed because the thread lock job finishes faster then the last job that runs.

brandonhilkert commented 7 years ago

Happy to poke around if you want to provide a test script!

nulian commented 7 years ago

Still need to take some time to build a example project but found a solution for it myself. Replaced the comparable shutdown_all part with this below.

queue.post(latch) do |l|
            while queue.busy_workers != 0 do
              sleep(1)
            end

            l.count_down
          end
end