socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.12k stars 86 forks source link

Sidekiq shutdown issue #321

Closed pineman closed 3 months ago

pineman commented 3 months ago

Hi!

Thank you for all the work in async ruby 😄

I'm facing an issue using async in sidekiq. My tasks return nil when sidekiq exits via SIGTERM. From what I've been able to piece together, I believe this is what's happening:

I can currently workaround this by raising Sidekiq::Shutdown myself when I detect the tasks' return value is nil (as I don't expect that to be ever be a valid return value in my code).

Sample code of my sidekiq job:

class HardJob
  include Sidekiq::Job

  def perform
    resp1, resp2 = Async do
      [Async { req }, Async { req }].map(&:wait)
    end.wait
    puts "tasks returned nil!" if resp1.nil? && resp2.nil?
  end

  def req
    uri = URI("https://httpbin.org/delay/10")
    Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
      http.request(Net::HTTP::Get.new(uri))
    end
  end
end

Here's a fresh rails project that reproduces the issue, if it helps. To reproduce:

Any insight would be greatly appreciated! Cheers!

ioquatix commented 3 months ago

I think I know what's going on here, let me see if I can fix it.

ioquatix commented 3 months ago

Can you please try release v2.12.1 to see if it fixes the issue? Thanks!

pineman commented 3 months ago

Yes, it does! Thanks so much for the quick fix 😄

ioquatix commented 3 months ago

No problem, thanks for the detailed report, it allowed me to figure out the issue quickly.