From bcace1dcee977afed032b07db70d1454fd76ff88 Mon Sep 17 00:00:00 2001 From: zaphod534 Date: Tue, 30 Nov 2021 11:47:35 +0100 Subject: [PATCH] fix: reset stream_id when the http2 connection is closed (#216) --- lib/pigeon/apns.ex | 13 ++++++++++++- lib/pigeon/fcm.ex | 13 ++++++++++++- lib/pigeon/legacy_fcm.ex | 13 ++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/pigeon/apns.ex b/lib/pigeon/apns.ex index fea27ec6..d7025ed9 100644 --- a/lib/pigeon/apns.ex +++ b/lib/pigeon/apns.ex @@ -206,7 +206,13 @@ defmodule Pigeon.APNS do case connect_socket(config) do {:ok, socket} -> Configurable.schedule_ping(config) - {:noreply, %{state | socket: socket}} + + state = + state + |> reset_stream_id() + |> Map.put(:socket, socket) + + {:noreply, state} {:error, reason} -> {:stop, reason} @@ -251,4 +257,9 @@ defmodule Pigeon.APNS do def inc_stream_id(%{stream_id: stream_id} = state) do %{state | stream_id: stream_id + 2} end + + @doc false + def reset_stream_id(state) do + %{state | stream_id: 1} + end end diff --git a/lib/pigeon/fcm.ex b/lib/pigeon/fcm.ex index 33ac67a0..aab7da20 100644 --- a/lib/pigeon/fcm.ex +++ b/lib/pigeon/fcm.ex @@ -158,7 +158,13 @@ defmodule Pigeon.FCM do case connect_socket(config) do {:ok, socket} -> Configurable.schedule_ping(config) - {:noreply, %{state | socket: socket}} + + state = + state + |> reset_stream_id() + |> Map.put(:socket, socket) + + {:noreply, state} {:error, reason} -> {:stop, reason} @@ -237,4 +243,9 @@ defmodule Pigeon.FCM do def inc_stream_id(%{stream_id: stream_id} = state) do %{state | stream_id: stream_id + 2} end + + @doc false + def reset_stream_id(state) do + %{state | stream_id: 1} + end end diff --git a/lib/pigeon/legacy_fcm.ex b/lib/pigeon/legacy_fcm.ex index e1ecf578..63672c3d 100644 --- a/lib/pigeon/legacy_fcm.ex +++ b/lib/pigeon/legacy_fcm.ex @@ -239,7 +239,13 @@ defmodule Pigeon.LegacyFCM do case connect_socket(config) do {:ok, socket} -> Configurable.schedule_ping(config) - {:noreply, %{state | socket: socket}} + + state = + state + |> reset_stream_id() + |> Map.put(:socket, socket) + + {:noreply, state} {:error, reason} -> {:stop, reason} @@ -284,4 +290,9 @@ defmodule Pigeon.LegacyFCM do def inc_stream_id(%{stream_id: stream_id} = state) do %{state | stream_id: stream_id + 2} end + + @doc false + def reset_stream_id(state) do + %{state | stream_id: 1} + end end