Skip to content

Commit c3aa792

Browse files
committed
Use polling to watch certificate paths
It's common for certificates to be rotated using symlinks and `FileSystemWatcher` doesn't resolve symlinks. Use polling, which does, but only for certificates since it has a CPU cost. Fixes dotnet#32351
1 parent bc64e69 commit c3aa792

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Servers/Kestrel/Core/src/Internal/CertificatePathWatcher.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ internal sealed partial class CertificatePathWatcher : IDisposable
2929

3030
public CertificatePathWatcher(IHostEnvironment hostEnvironment, ILogger<CertificatePathWatcher> logger)
3131
: this(
32-
hostEnvironment.ContentRootPath,
33-
logger,
34-
dir => Directory.Exists(dir) ? new PhysicalFileProvider(dir, ExclusionFilters.None) : null)
32+
hostEnvironment.ContentRootPath,
33+
logger,
34+
dir => Directory.Exists(dir)
35+
? new PhysicalFileProvider(dir, ExclusionFilters.None)
36+
{
37+
UseActivePolling = true,
38+
UsePollingFileWatcher = true,
39+
}
40+
: null)
3541
{
3642
}
3743

src/Servers/Kestrel/Kestrel/test/KestrelConfigurationLoaderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ public async Task CertificateChangedOnDisk(bool reloadOnChange)
894894

895895
if (reloadOnChange)
896896
{
897-
await fileTcs.Task.DefaultTimeout();
897+
await fileTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(10)); // Needs to be meaningfully longer than the polling period - 4 seconds
898898
}
899899
else
900900
{

0 commit comments

Comments
 (0)