handle connection failures inside the main loop