fix race condition in cancellation