ostinelli / apnotic

A Ruby APNs HTTP/2 gem able to provide instant feedback.
MIT License
479 stars 94 forks source link

Stuck if calling a Sidekiq worker inside push.on(:response) #60

Closed benoittgt closed 6 years ago

benoittgt commented 6 years ago

Hello,

This probably a known issue/behavior https://github.com/ostinelli/apnotic/issues/14 but I have this kind of code:

# this function is called from a Sidekiq worker

    notification = Apnotic::MdmNotification.new(...)
    push = connection.prepare_push(notification)
    push.on(:response) do |response|
      if response.ok?
        XWorker.perform_async(device.id) # 🔒
      end
    end
    connection.join
    connection.close

But the worker (XWorker) "lock" the action and we loop forever in https://github.com/ostinelli/net-http2/blob/master/lib/net-http2/client.rb#L59.

So instead I have to run the code immediately and avoid using the worker. Is it normal? I tried to understand without finding the solution.

ostinelli commented 6 years ago

The README contains an example on how to do async calls:

# prepare push
push = connection.prepare_push(notification)
push.on(:response) do |response|
  # read the response
  response.ok?      # => true
  response.status   # => '200'
  response.headers  # => {":status"=>"200", "apns-id"=>"6f2cd350-bfad-4af0-a8bc-0d501e9e1799"}
  response.body     # => ""
end

# send
connection.push_async(push)

Why are you calling push_async inside of a callback?

benoittgt commented 6 years ago

Thanks.

Closing for now because our implementation doesn't follow the recommended way.