Avoid deadlock on app shutdown