Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed leaked in pool manager
  • Loading branch information
ManickaP committed Nov 23, 2021
commit 719b0c21a64068405e5d3f4c64418d40bcfeb28f
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,18 @@ public bool CleanCacheAndDisposeIfUnused()
if (NetEventSource.Log.IsEnabled()) Trace("Cleaning pool.");
Monitor.Enter(SyncObj, ref tookLock);

// If there are now no connections associated with this pool, we can dispose of it. We
// avoid aggressively cleaning up pools that have recently been used but currently aren't;
// if a pool was used since the last time we cleaned up, give it another chance. New pools
// start out saying they've recently been used, to give them a bit of breathing room and time
// for the initial collection to be added to it.
if (_associatedConnectionCount == 0 && !_usedSinceLastCleanup && _http2Connections == null)
{
Debug.Assert(list.Count == 0, $"Expected {nameof(list)}.{nameof(list.Count)} == 0");
_disposed = true;
return true; // Pool is disposed of. It should be removed.
}

// Get the current time. This is compared against each connection's last returned
// time to determine whether a connection is too old and should be closed.
long nowTicks = Environment.TickCount64;
Expand Down Expand Up @@ -1811,18 +1823,6 @@ public bool CleanCacheAndDisposeIfUnused()
// At this point, good connections have been moved below freeIndex, and garbage connections have
// been added to the dispose list, so clear the end of the list past freeIndex.
list.RemoveRange(freeIndex, list.Count - freeIndex);

// If there are now no connections associated with this pool, we can dispose of it. We
// avoid aggressively cleaning up pools that have recently been used but currently aren't;
// if a pool was used since the last time we cleaned up, give it another chance. New pools
// start out saying they've recently been used, to give them a bit of breathing room and time
// for the initial collection to be added to it.
if (_associatedConnectionCount == 0 && !_usedSinceLastCleanup && _http2Connections == null)
{
Debug.Assert(list.Count == 0, $"Expected {nameof(list)}.{nameof(list.Count)} == 0");
_disposed = true;
return true; // Pool is disposed of. It should be removed.
}
}

// Reset the cleanup flag. Any pools that are empty and not used since the last cleanup
Expand Down