Skip to content

Commit 00e6f33

Browse files
committed
fix(watcher): set default timeout for watcher service
- Changed the `WatcherTimeout` property to provide a default value of 1800 seconds if no timeout is specified. - Updated cancellation token logic to use the new `WatcherTimeout` value, ensuring consistent behavior in resource watching operations.
1 parent a8751bc commit 00e6f33

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ES.Kubernetes.Reflector/Core/Watchers/WatcherBackgroundService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class WatcherBackgroundService<TResource, TResourceList>(
2020
protected readonly ILogger Logger = logger;
2121
protected readonly IMediator Mediator = mediator;
2222

23-
protected int? WatcherTimeout => options.CurrentValue.Watcher?.Timeout;
23+
protected int WatcherTimeout => options.CurrentValue.Watcher?.Timeout ?? 1800;
2424

2525
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2626
{
@@ -37,13 +37,13 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
3737
{
3838
Logger.LogInformation("Requesting {type} resources", typeof(TResource).Name);
3939

40-
using var delayTokenCts = new CancellationTokenSource(TimeSpan.FromSeconds(WatcherTimeout ?? 900));
41-
using var sleepCts =
42-
CancellationTokenSource.CreateLinkedTokenSource(stoppingToken, delayTokenCts.Token);
40+
41+
using var absoluteTimeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(WatcherTimeout + 3));
42+
using var cancellationCts = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken, absoluteTimeoutCts.Token);
4343
using var client = scope.ServiceProvider.GetRequiredService<IKubernetes>();
4444

4545
using var watcher = OnGetWatcher(client, stoppingToken);
46-
var watchList = watcher.WatchAsync<TResource, TResourceList>(cancellationToken: sleepCts.Token);
46+
var watchList = watcher.WatchAsync<TResource, TResourceList>(cancellationToken: cancellationCts.Token);
4747

4848
await foreach (var (type, item) in watchList)
4949
await Mediator.Publish(new WatcherEvent

0 commit comments

Comments
 (0)