fix race condition on stopping.