Closed as not planned
Description
Hi!
I think that current implementation of Watcher.Dispose()
is a bit lacking:
csharp/src/KubernetesClient/Watcher.cs
Lines 217 to 229 in 541abb0
specifically between _cts?.Cancel()
and _cts?.Dispose()
calls, we should await for the _watcherLoop
task to finish. Otherwise it might attempt to access the Token of already disposed _cts, which is generally undesirable.
Also possible exception would be unobserved, which in turn may be a problem for applications with strict policies on unobserved exceptions.
What do you think? Will you consider a PR like this:
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_cts.Cancel();
try
{
_watcherLoop.GetAwaiter().GetResult();
}
catch
{
//consume possible exception
}
_cts.Dispose();
}
disposedValue = true;
}
}