Fix the task termination bug.