The loop exits when:
 1. the task succeeds
 2. the task fails
 3. the task query fails
 4. the sync is cancelled

Do you think there are other conditions that need to be considered?