SemaphoreSlim.Dispose() is not thread-safe and may cause WaitAsync(CancellationToken) not being cancelled when SemaphoreSlim.Dispose is invoked immediately after CancellationTokenSource.Cancel. See https://github.com/dotnet/runtime/issues/59639
SemaphoreSlim.Dispose() only disposes it's wait handle, which is not initialized unless its AvailableWaitHandle property is read, and SSH library doesn't use it.
Fix for https://github.com/microsoft/basis-planning/issues/769
SemaphoreSlim.Dispose()
is not thread-safe and may causeWaitAsync(CancellationToken)
not being cancelled whenSemaphoreSlim.Dispose
is invoked immediately afterCancellationTokenSource.Cancel
. See https://github.com/dotnet/runtime/issues/59639SemaphoreSlim.Dispose()
only disposes it's wait handle, which is not initialized unless itsAvailableWaitHandle
property is read, and SSH library doesn't use it.The fix is just to not dispose slim semaphores.