Avoid deadlock on shutdown