Skip to content

Commit

Permalink
fix: reset stream_id when the http2 connection is closed (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaphod534 committed Nov 30, 2021
1 parent 54735f8 commit bcace1d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/pigeon/apns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
13 changes: 12 additions & 1 deletion lib/pigeon/fcm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
13 changes: 12 additions & 1 deletion lib/pigeon/legacy_fcm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

0 comments on commit bcace1d

Please sign in to comment.