Skip to content

Commit

Permalink
Correctly reuse the session (#558)
Browse files Browse the repository at this point in the history
Before this change, when a user disconnect abruptly, the session would
linger. If the user then reconnect before the session terminates, it
would not register with the new session, and the session would get
terminated as if the user did not reconnect.
  • Loading branch information
geekingfrog authored Jan 22, 2025
1 parent 7784508 commit 1710fa5
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/teiserver/player/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ defmodule Teiserver.Player.Session do
end

@impl true
def handle_call({:replace, _}, _from, state) when is_nil(state.conn_pid),
do: {:reply, :ok, state}

def handle_call({:replace, new_conn_pid}, _from, state) do
Process.demonitor(state.mon_ref, [:flush])

mon_ref = Process.monitor(new_conn_pid)
Logger.info("session reused for player #{state.user.id}")

{:reply, :ok, %{state | conn_pid: new_conn_pid, mon_ref: mon_ref}}
end
Expand Down

0 comments on commit 1710fa5

Please sign in to comment.