Skip to content

Commit 009576a

Browse files
committed
Dispose connection from the pool in a serate task to not to block the caller (scavenge timer callback)
1 parent 6264afd commit 009576a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,11 @@ public bool CleanCacheAndDisposeIfUnused()
19791979
}
19801980

19811981
// Dispose the stale connections outside the pool lock, to avoid holding the lock too long.
1982-
toDispose?.ForEach(c => c.Dispose());
1982+
// Dispose them asynchronously to not to block the caller on closing the SslStream or NetworkStream.
1983+
if (toDispose is not null)
1984+
{
1985+
Task.Run(() => toDispose.ForEach(c => c.Dispose()));
1986+
}
19831987

19841988
// Pool is active. Should not be removed.
19851989
return false;

0 commit comments

Comments
 (0)