Skip to content

Commit 474ce6d

Browse files
committed
Ignores messages with stale join ref
1 parent 98088bc commit 474ce6d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/phoenix_live_view/channel.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ defmodule Phoenix.LiveView.Channel do
129129
{:stop, {:shutdown, :draining}, state}
130130
end
131131

132+
def handle_info(
133+
%Message{topic: topic, join_ref: message_join_ref} = msg,
134+
%{topic: topic, join_ref: state_join_ref} = state
135+
)
136+
when message_join_ref != state_join_ref do
137+
Logger.debug(
138+
"Ignoring message with stale join_ref: #{message_join_ref} != expected #{state_join_ref}"
139+
)
140+
141+
{:noreply, reply(state, msg.ref, :error, %{reason: "stale"})}
142+
end
143+
132144
def handle_info(%Message{topic: topic, event: "phx_leave"} = msg, %{topic: topic} = state) do
133145
send(state.socket.transport_pid, {:socket_close, self(), {:shutdown, :left}})
134146
reply(state, msg.ref, :ok, %{})

0 commit comments

Comments
 (0)