Fix heap-use-after-free on server shutdown.