fix a few rare race conditions that could lead to a lockup