Fixed race that lead to deadlock.