Fix a bug around cancelling task.