     {:disconnect, {:error, reason}, state}
   end
 
+  defp flush_messages_from_receiver(%{receiver: receiver} = state) do
+    receive do
+      {:receiver, ^receiver, _msg} -> flush_messages_from_receiver(state)
+    after
+      0 -> :ok
+    end
+  end
+
   defp calc_next_backoff(current_backoff, backoff_max) do
     next_exponential_backoff = round(current_backoff * @backoff_exponent)
 

    ]

    :ok = :gen_tcp.close(state.socket)
    :ok = SharedState.disconnect_clients_and_stop(state.shared_state)

    state = %{state | socket: nil, current_backoff: @initial_backoff}

      :ok ->
        {:noreply, state}
      {:error, _reason} = error ->
        {:disconnect, error, state}
    end
  end

