Fix infinite loop when max_reconnect_attempts is reached.