Fix subtle bad concurrency cases