Skip to content

Commit 95687cd

Browse files
committed
CSHARP-1375: Simplified SemaphoreSlimRequest Dispose method.
1 parent 330405f commit 95687cd

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/MongoDB.Driver.Core/Core/Misc/SemaphoreSlimRequest.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,10 @@ public SemaphoreSlimRequest(SemaphoreSlim semaphore, CancellationToken cancellat
6464
/// <inheritdoc/>
6565
public void Dispose()
6666
{
67+
_disposeCancellationTokenSource.Cancel(); // if we haven't gotten the lock by now we no longer want it
6768
if (_task.Status == TaskStatus.RanToCompletion)
6869
{
69-
_semaphore.Release(); // we already had the lock
70-
}
71-
else
72-
{
73-
_disposeCancellationTokenSource.Cancel();
74-
try
75-
{
76-
_task.GetAwaiter().GetResult(); // will throw OperationCanceledException if we didn't get the lock
77-
_semaphore.Release(); // we got the lock while we were trying to cancel the request
78-
}
79-
catch (OperationCanceledException)
80-
{
81-
// ignore
82-
}
70+
_semaphore.Release();
8371
}
8472

8573
_disposeCancellationTokenSource.Dispose();

0 commit comments

Comments
 (0)