Fix infinite loop when can't run all tasks