Retry and improve protection against query errors.