Yes indeed - it would require opening two tabs/connections at the same time tough, and the channel crash would make a rejoin which wouldn’t then crash, but I agree, it’s better to take care of it right there as well.
Just use this part…
case GenServer.start(__MODULE__, {n_id, self()}, name: gen_serv_ref(id)) do
{:ok, pid} -> {:ok, pid}
{:error, {:already_started, pid}} -> {:ok, pid}
end
PS: The BEAM forbid processes with the same name, there is no need to check if there is already one present. See this post for a longer response
1 Like