Fix potential crash after shutdown