     end
   end
 
-  defp handle_in({pid, ref}, %{event: "phx_join", topic: topic} = message, state, socket) do
+  defp handle_in({pid, _ref}, %{event: "phx_join", topic: topic} = message, state, socket) do
     receive do
       {:socket_close, ^pid, _reason} -> :ok
     after
       0 ->
         Logger.debug(fn ->
           "Duplicate channel join for topic \"#{topic}\" in #{inspect(socket.handler)}. " <>
-            "Closing existing channel for new join."
+          "Closing existing channel for new join."
         end)
     end
 
     :ok = shutdown_duplicate_channel(pid)
-    state = delete_channel(state, pid, topic, ref)
-    handle_in(nil, message, state, socket)
+    {:push, {opcode, payload}, {new_state, new_socket}} = socket_close(pid, {state, socket})
+    send(self(), {:socket_push, opcode, payload})
+    handle_in(nil, message, new_state, new_socket)
   end
 
   defp handle_in({pid, _ref}, message, state, socket) do

        receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
    end
  end
end

  end

  def __info__({:socket_close, pid, _reason}, {state, socket}) do
    socket_close(pid, {state, socket})
  end

  def __info__(:garbage_collect, state) do
