Fixed deadlock on exit