diff --git a/source/Halibut/Transport/PollingClient.cs b/source/Halibut/Transport/PollingClient.cs index de672bbf..3b2fa3cb 100644 --- a/source/Halibut/Transport/PollingClient.cs +++ b/source/Halibut/Transport/PollingClient.cs @@ -25,7 +25,6 @@ public class PollingClient : IPollingClient readonly Func createRetryPolicy; readonly AsyncHalibutFeature asyncHalibutFeature; - RequestCancellationTokens? requestCancellationTokens; public PollingClient(Uri subscription, ISecureClient secureClient, Func handleIncomingRequest, ILog log, CancellationToken cancellationToken, Func createRetryPolicy, AsyncHalibutFeature asyncHalibutFeature) { @@ -64,8 +63,7 @@ public void Start() } else { - requestCancellationTokens = new RequestCancellationTokens(workingCancellationTokenSource.Token, workingCancellationTokenSource.Token); - pollingClientLoopTask = Task.Run(async () => await ExecutePollingLoopAsyncCatchingExceptions(requestCancellationTokens)); + pollingClientLoopTask = Task.Run(async () => await ExecutePollingLoopAsyncCatchingExceptions(workingCancellationTokenSource.Token)); } } @@ -74,7 +72,6 @@ public void Dispose() working = false; Try.CatchingError(workingCancellationTokenSource.Cancel, _ => { }); Try.CatchingError(workingCancellationTokenSource.Dispose, _ => { }); - Try.CatchingError(() => requestCancellationTokens?.Dispose(), _ => { }); } void ExecutePollingLoop(object ignored) @@ -123,11 +120,11 @@ void ExecutePollingLoop(object ignored) /// Runs ExecutePollingLoopAsync but catches any exception that falls out of it, log here /// rather than let it be unobserved. We are not expecting an exception but just in case. /// - async Task ExecutePollingLoopAsyncCatchingExceptions(RequestCancellationTokens requestCancellationTokens) + async Task ExecutePollingLoopAsyncCatchingExceptions(CancellationToken cancellationToken) { try { - await ExecutePollingLoopAsync(requestCancellationTokens); + await ExecutePollingLoopAsync(cancellationToken); } catch (Exception e) { @@ -135,8 +132,9 @@ async Task ExecutePollingLoopAsyncCatchingExceptions(RequestCancellationTokens r } } - async Task ExecutePollingLoopAsync(RequestCancellationTokens requestCancellationTokens) + async Task ExecutePollingLoopAsync(CancellationToken cancellationToken) { + using var requestCancellationTokens = new RequestCancellationTokens(cancellationToken, cancellationToken); var retry = createRetryPolicy(); var sleepFor = TimeSpan.Zero; while (!cancellationToken.IsCancellationRequested)