codedge-llc / pigeon

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

APNS fail with too_many_provider_token_updates #204

Closed ruslandoga closed 3 years ago

ruslandoga commented 3 years ago

šŸ‘‹

Environment

Elixir 1.12.2 (compiled with Erlang/OTP 24)

* Operating system: `macOS 11.5.2 (20G95)`

* Config:

Before https://github.com/ruslandoga/test3/pull/267 I used the same key for both prod and sandbox envs. But that shouldn't have been the problem since the `token_storage_key` should've been the same for both envs, so the same token would've been used https://github.com/codedge-llc/pigeon/blob/589752b95bec5f8474b39cee0b77e8fa1f81bd69/lib/pigeon/apns/jwt_config.ex#L191

* Pigeon version:

I'm using a [fork of v1.6](https://github.com/ruslandoga/pigeon/commit/b3ab50e704cd631f703ade25fe28011509992027) which removed poison, httpoison, and adm. Token refresh logic between master and v1.6 seems to have stayed the same though.

### Current behavior

APNS pushes [fail](https://github.com/ruslandoga/test3/blob/71447605705253bcae383b6a8ee81712177cf86f/lib/t/push_notifications/apns_job.ex#L19-L27) with reason `too_many_provider_token_updates`:

CaseClauseError: no case clause matching: %Pigeon.APNS.Notification{collapse_id: "[REDACTED]", device_token: "E069[REDACTED]5783", expiration: nil, id: nil, payload: %{"aps" => %{"alert" => %{"body" => "[REDACTED]", "title" => "[REDACTED]"}, "badge" => 1, "mutable-content" => 1}}, priority: nil, push_type: "alert", response: :too_many_provider_token_updates, topic: "app.[REDACTED].ios"} File "lib/t/push_notifications/apns_job.ex", line 20, in T.PushNotifications.APNSJob.perform/1 case APNS.push_alert(template, device, data) do File "lib/oban/queue/executor.ex", line 209, in Oban.Queue.Executor.perform_inline/2 File "lib/oban/queue/executor.ex", line 197, in Oban.Queue.Executor.perform_inline/2 File "lib/oban/queue/executor.ex", line 82, in Oban.Queue.Executor.call/1 File "lib/task/supervised.ex", line 90, in Task.Supervised.invoke_mfa/2 File "lib/task/supervised.ex", line 35, in Task.Supervised.reply/5 File "proc_lib.erl", line 226, in :proc_lib.init_p_do_apply/3



### Expected behavior

Just would like to know what could be the problem.
ruslandoga commented 3 years ago

I've checked Pigeon.APNS.JWTConfig, and it seems the token is updated at most once every 3590 seconds, and the token is synced through an agent.