codedge-llc / pigeon

iOS and Android push notifications for Elixir
https://hex.pm/packages/pigeon
MIT License
646 stars 146 forks source link

How to handle resend on push fail #10

Closed Lida closed 8 years ago

Lida commented 8 years ago

On dev environment, I sometimes get the following timeout

[error] GenServer :apns_worker terminating
** (MatchError) no match of right hand side value: {:error, "timeout."}
    (pigeon) lib/pigeon/apns_worker.ex:74: Pigeon.APNSWorker.send_push/3
    (pigeon) lib/pigeon/apns_worker.ex:54: Pigeon.APNSWorker.handle_cast/2

Is there an exponential backoff retry mechanism on Pigeon planned? Or is there at least a way to find out the push failed from the API?

hpopp commented 8 years ago

Exponential backoff has been on my list for a while. I'll go ahead and roll it into the next release.

Right now pigeon doesn't play very nice when an SSL connection fails. I was able to recreate this exact error by disabling my internet after :apns_worker starts. I'm thinking the new functionality will be a maximum of 10 retries, and then a normal error tuple in the on_response.

hpopp commented 8 years ago

Implementing exponential backoff was a bit more unreliable than anticipated. For now I fixed the worker crash if the connection times out. Erlang's :ssl.send/2 will eventually send the push if the connection ever becomes available, but because it doesn't track sent pushes, I don't yet have a way to link the server response to the on_response function.

I'm planning on doing some major overhaul of the HTTP2 code before v1.0. This should finally get resolved then.