diff --git a/pkgs/sdk/server/src/Internal/DataSources/FileDataSource.cs b/pkgs/sdk/server/src/Internal/DataSources/FileDataSource.cs index 04cc81df..91cb989b 100644 --- a/pkgs/sdk/server/src/Internal/DataSources/FileDataSource.cs +++ b/pkgs/sdk/server/src/Internal/DataSources/FileDataSource.cs @@ -26,6 +26,7 @@ internal sealed class FileDataSource : IDataSource private volatile bool _started; private volatile bool _loadedValidData; private volatile int _lastVersion; + private object _updateLock = new object(); public FileDataSource(IDataSourceUpdates dataSourceUpdates, FileDataTypes.IFileReader fileReader, List paths, bool autoUpdate, Func alternateParser, bool skipMissingPaths, @@ -88,35 +89,39 @@ private void Dispose(bool disposing) private void LoadAll() { - var version = Interlocked.Increment(ref _lastVersion); - var flags = new Dictionary(); - var segments = new Dictionary(); - foreach (var path in _paths) + lock (_updateLock) { - try - { - var content = _fileReader.ReadAllText(path); - _logger.Debug("file data: {0}", content); - var data = _parser.Parse(content, version); - _dataMerger.AddToData(data, flags, segments); - } - catch (FileNotFoundException) when (_skipMissingPaths) + var version = Interlocked.Increment(ref _lastVersion); + var flags = new Dictionary(); + var segments = new Dictionary(); + foreach (var path in _paths) { - _logger.Debug("{0}: {1}", path, "File not found"); - } - catch (Exception e) - { - LogHelpers.LogException(_logger, "Failed to load " + path, e); - return; + try + { + var content = _fileReader.ReadAllText(path); + _logger.Debug("file data: {0}", content); + var data = _parser.Parse(content, version); + _dataMerger.AddToData(data, flags, segments); + } + catch (FileNotFoundException) when (_skipMissingPaths) + { + _logger.Debug("{0}: {1}", path, "File not found"); + } + catch (Exception e) + { + LogHelpers.LogException(_logger, "Failed to load " + path, e); + return; + } } + + var allData = new FullDataSet( + ImmutableDictionary.Create>() + .SetItem(DataModel.Features, new KeyedItems(flags)) + .SetItem(DataModel.Segments, new KeyedItems(segments)) + ); + _dataSourceUpdates.Init(allData); + _loadedValidData = true; } - var allData = new FullDataSet( - ImmutableDictionary.Create>() - .SetItem(DataModel.Features, new KeyedItems(flags)) - .SetItem(DataModel.Segments, new KeyedItems(segments)) - ); - _dataSourceUpdates.Init(allData); - _loadedValidData = true; } private void TriggerReload()