fix a potential deadlock bug.