fix deadlock on exit