microsoft / dev-tunnels-ssh

SSH library for dev-tunnels
MIT License
131 stars 17 forks source link

Do not dispose SemaphoreSlim #44

Closed IlyaBiryukov closed 1 year ago

IlyaBiryukov commented 1 year ago

Fix for https://github.com/microsoft/basis-planning/issues/769

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.

The fix is just to not dispose slim semaphores.