           Utils.format_error(reason),
         ]
 
+        # If this is the first time we connect, then we just retry after the
+        # initial backoff (there's no need to calculate backoff and so on).
         if info == :init do
           {:backoff, @initial_backoff, %{state | current_backoff: @initial_backoff}}
         else
-          backoff_max = state.opts[:backoff_max]
-          next_exponential_backoff = round(state.current_backoff * @backoff_exponent)
-          next_backoff =
-            if backoff_max == :infinity do
-              next_exponential_backoff
-            else
-              min(next_exponential_backoff, backoff_max)
-            end
+          next_backoff = calc_next_backoff(state.current_backoff, state.opts[:backoff_max])
           {:backoff, next_backoff, %{state | current_backoff: next_backoff}}
         end
       other ->

  defp handle_msg_from_receiver({:tcp_error, socket, reason}, %{socket: socket} = state) do
    {:disconnect, {:error, reason}, state}
  end
end

    end
  end

  defp start_receiver_and_hand_socket(socket, timeout_store) do
    {:ok, receiver} = Receiver.start_link(sender: self(), socket: socket, timeout_store: timeout_store)
    :ok = :gen_tcp.controlling_process(socket, receiver)
    receiver
  end

  defp handle_msg_from_receiver({:tcp_closed, socket}, %{socket: socket} = state) do
