private void UpdateSnapshot(IReadOnlyList <ProxyRoute> routes, IReadOnlyList <Cluster> clusters)
        {
            // Prevent overlapping updates
            lock (_lockObject)
            {
                using var oldToken = _changeToken;
                _changeToken       = new CancellationTokenSource();
                _snapshot          = new ConfigurationSnapshot()
                {
                    Routes      = routes,
                    Clusters    = clusters,
                    ChangeToken = new CancellationChangeToken(_changeToken.Token)
                };

                try
                {
                    oldToken?.Cancel(throwOnFirstException: false);
                }
                catch (Exception ex)
                {
                    Log.ErrorSignalingChange(_logger, ex);
                }
            }

            _initalConfigLoadTcs.TrySetResult(0);
        }
    private void UpdateSnapshot()
    {
        // Prevent overlapping updates, especially on startup.
        lock (_lockObject)
        {
            Log.LoadData(_logger);
            ConfigurationSnapshot newSnapshot;
            try
            {
                newSnapshot = new ConfigurationSnapshot();

                foreach (var section in _configuration.GetSection("Clusters").GetChildren())
                {
                    newSnapshot.Clusters.Add(CreateCluster(section));
                }

                foreach (var section in _configuration.GetSection("Routes").GetChildren())
                {
                    newSnapshot.Routes.Add(CreateRoute(section));
                }
            }
            catch (Exception ex)
            {
                Log.ConfigurationDataConversionFailed(_logger, ex);

                // Re-throw on the first time load to prevent app from starting.
                if (_snapshot == null)
                {
                    throw;
                }

                return;
            }

            var oldToken = _changeToken;
            _changeToken            = new CancellationTokenSource();
            newSnapshot.ChangeToken = new CancellationChangeToken(_changeToken.Token);
            _snapshot = newSnapshot;

            try
            {
                oldToken?.Cancel(throwOnFirstException: false);
            }
            catch (Exception ex)
            {
                Log.ErrorSignalingChange(_logger, ex);
            }
        }
    }