Fixed potential deadlock while exitting