Skip to content

Commit e0bc6fe

Browse files
committed
CSHARP-3810: Prevent pool pruning from acquiring a slot in _maxConnectionsQueue
1 parent f2349ad commit e0bc6fe

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/MongoDB.Driver.Core/Core/ConnectionPools/ExclusiveConnectionPool.Helpers.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public void Clear()
745745
}
746746
}
747747

748-
public void Prune()
748+
public void Prune(CancellationToken cancellationToken)
749749
{
750750
PooledConnection[] expiredConnections;
751751
lock (_lock)
@@ -755,6 +755,8 @@ public void Prune()
755755

756756
foreach (var connection in expiredConnections)
757757
{
758+
cancellationToken.ThrowIfCancellationRequested();
759+
758760
lock (_lock)
759761
{
760762
// At this point connection is always expired and might be disposed

src/MongoDB.Driver.Core/Core/ConnectionPools/ExclusiveConnectionPool.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private async Task MaintainSizeAsync(CancellationToken cancellationToken)
299299
{
300300
try
301301
{
302-
await PrunePoolAsync(cancellationToken).ConfigureAwait(false);
302+
_connectionHolder.Prune(cancellationToken);
303303
await EnsureMinSizeAsync(cancellationToken).ConfigureAwait(false);
304304
}
305305
catch
@@ -315,20 +315,6 @@ private async Task MaintainSizeAsync(CancellationToken cancellationToken)
315315
}
316316
}
317317

318-
private async Task PrunePoolAsync(CancellationToken cancellationToken)
319-
{
320-
using (var poolAwaiter = _maxConnectionsQueue.CreateAwaiter())
321-
{
322-
var entered = await poolAwaiter.WaitSignaledAsync(TimeSpan.FromMilliseconds(20), cancellationToken).ConfigureAwait(false);
323-
if (!entered)
324-
{
325-
return;
326-
}
327-
328-
_connectionHolder.Prune();
329-
}
330-
}
331-
332318
private async Task EnsureMinSizeAsync(CancellationToken cancellationToken)
333319
{
334320
var minTimeout = TimeSpan.FromMilliseconds(20);

0 commit comments

Comments
 (0)