• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ThreeMammals / Ocelot / 26761608736

01 Jun 2026 02:34PM UTC coverage: 0.0% (-95.4%) from 95.403%
26761608736

Pull #2394

github

web-flow
Merge e39fc0db2 into e4022a7d8
Pull Request #2394: Harden `FileConfigurationPoller` against timer reentrancy and callback thread leaks, and stabilize `TimeoutDelegatingHandler` timeout test

0 of 7112 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs
1
using Microsoft.AspNetCore.Hosting;
2
using Newtonsoft.Json;
3
using Ocelot.Configuration.ChangeTracking;
4
using Ocelot.Configuration.File;
5
using Ocelot.DependencyInjection;
6
using FileIO = System.IO.File;
7

8
namespace Ocelot.Configuration.Repository;
9
public class DiskFileConfigurationRepository : IFileConfigurationRepository, IDisposable
10
{
11
    private FileInfo _ocelotFile;
12
    private FileInfo _environmentFile;
13
    private readonly IWebHostEnvironment _hostingEnvironment;
14
    private readonly IOcelotConfigurationChangeTokenSource _changeTokenSource;
15
    private readonly SemaphoreSlim _semaphore = new(1, 1); // 1 concurrent access
×
16

17
    public DiskFileConfigurationRepository(IWebHostEnvironment hostingEnvironment, IOcelotConfigurationChangeTokenSource changeTokenSource)
×
18
    {
×
19
        _hostingEnvironment = hostingEnvironment;
×
20
        _changeTokenSource = changeTokenSource;
×
21
        Initialize(AppContext.BaseDirectory);
×
22
    }
×
23

24
    public DiskFileConfigurationRepository(IWebHostEnvironment hostingEnvironment, IOcelotConfigurationChangeTokenSource changeTokenSource, string folder)
×
25
    {
×
26
        _hostingEnvironment = hostingEnvironment;
×
27
        _changeTokenSource = changeTokenSource;
×
28
        Initialize(folder);
×
29
    }
×
30

31
    private void Initialize(string folder)
32
    {
×
33
        folder ??= AppContext.BaseDirectory;
×
34
        _ocelotFile = new FileInfo(Path.Combine(folder, ConfigurationBuilderExtensions.PrimaryConfigFile));
×
35

36
        var envFile = !string.IsNullOrEmpty(_hostingEnvironment.EnvironmentName)
×
37
            ? string.Format(ConfigurationBuilderExtensions.EnvironmentConfigFile, _hostingEnvironment.EnvironmentName)
×
38
            : ConfigurationBuilderExtensions.PrimaryConfigFile;
×
39

40
        _environmentFile = new FileInfo(Path.Combine(folder, envFile));
×
41
    }
×
42

43
    public FileConfiguration Get()
44
    {
×
45
        string json;
46
        _semaphore.Wait();
×
47
        try
48
        {
×
49
            json = FileIO.ReadAllText(_environmentFile.FullName);
×
50
        }
×
51
        finally
52
        {
×
53
            _semaphore.Release();
×
54
        }
×
55

56
        return JsonConvert.DeserializeObject<FileConfiguration>(json);
×
57
    }
×
58

59
    public async Task<FileConfiguration> GetAsync(CancellationToken cancellationToken = default)
60
    {
×
61
        string json;
62
        await _semaphore.WaitAsync(cancellationToken);
×
63
        try
64
        {
×
65
            json = await FileIO.ReadAllTextAsync(_environmentFile.FullName, cancellationToken);
×
66
        }
×
67
        finally
68
        {
×
69
            _semaphore.Release();
×
70
        }
×
71

72
        return JsonConvert.DeserializeObject<FileConfiguration>(json);
×
73
    }
×
74

75
    public void Set(FileConfiguration configuration)
76
    {
×
77
        var json = JsonConvert.SerializeObject(configuration, Formatting.Indented);
×
78
        _semaphore.Wait();
×
79
        try
80
        {
×
81
            if (_environmentFile.Exists)
×
82
                _environmentFile.Delete();
×
83

84
            FileIO.WriteAllText(_environmentFile.FullName, json);
×
85

86
            if (_ocelotFile.Exists)
×
87
                _ocelotFile.Delete();
×
88

89
            FileIO.WriteAllText(_ocelotFile.FullName, json);
×
90
        }
×
91
        finally
92
        {
×
93
            _semaphore.Release();
×
94
        }
×
95

96
        _changeTokenSource.Activate();
×
97
    }
×
98

99
    public async Task SetAsync(FileConfiguration configuration, CancellationToken cancellationToken = default)
100
    {
×
101
        var json = JsonConvert.SerializeObject(configuration, Formatting.Indented);
×
102
        await _semaphore.WaitAsync(cancellationToken);
×
103
        try
104
        {
×
105
            if (_environmentFile.Exists)
×
106
                _environmentFile.Delete();
×
107

108
            await FileIO.WriteAllTextAsync(_environmentFile.FullName, json, cancellationToken);
×
109

110
            if (_ocelotFile.Exists)
×
111
                _ocelotFile.Delete();
×
112

113
            await FileIO.WriteAllTextAsync(_ocelotFile.FullName, json, cancellationToken);
×
114
        }
×
115
        finally
116
        {
×
117
            _semaphore.Release();
×
118
        }
×
119

120
        _changeTokenSource.Activate();
×
121
    }
×
122

123
    public void Dispose()
124
    {
×
125
        _semaphore.Dispose();
×
126
        GC.SuppressFinalize(this);
×
127
    }
×
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc