Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] [HTTP] Scavenge fix #62008

Merged
merged 3 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,12 @@ public bool CleanCacheAndDisposeIfUnused()
}

// Dispose the stale connections outside the pool lock, to avoid holding the lock too long.
toDispose?.ForEach(c => c.Dispose());
// Dispose them asynchronously to not to block the caller on closing the SslStream or NetworkStream.
if (toDispose is not null)
{
Task.Factory.StartNew(static s => ((List<HttpConnectionBase>)s!).ForEach(c => c.Dispose()), toDispose,
CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
}

// Pool is active. Should not be removed.
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private void SetCleaningTimer(TimeSpan timeout)
{
try
{
_cleaningTimer!.Change(timeout, timeout);
_cleaningTimer!.Change(timeout, Timeout.InfiniteTimeSpan);
_timerIsRunning = timeout != Timeout.InfiniteTimeSpan;
}
catch (ObjectDisposedException)
Expand Down Expand Up @@ -492,13 +492,10 @@ private void RemoveStalePools()
}
}

// Stop running the timer if we don't have any pools to clean up.
// Restart the timer if we have any pools to clean up.
lock (SyncObj)
{
if (_pools.IsEmpty)
{
SetCleaningTimer(Timeout.InfiniteTimeSpan);
}
SetCleaningTimer(!_pools.IsEmpty ? _cleanPoolTimeout : Timeout.InfiniteTimeSpan);
}

// NOTE: There is a possible race condition with regards to a pool getting cleaned up at the same
Expand Down