Fix exception on shutdown.