Fix lockup on shutdown
