Fix a race condition on shutdown.