Commit 877a5630 authored by Honfika's avatar Honfika

fix for #556?

parent 721e395f
...@@ -184,13 +184,12 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -184,13 +184,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (cache.TryGetValue(cacheKey, out var existingConnections)) if (cache.TryGetValue(cacheKey, out var existingConnections))
{ {
// +3 seconds for potential delay after getting connection
var cutOff = DateTime.Now.AddSeconds(-proxyServer.ConnectionTimeOutSeconds + 3);
while (existingConnections.Count > 0) while (existingConnections.Count > 0)
{ {
if (existingConnections.TryDequeue(out var recentConnection)) if (existingConnections.TryDequeue(out var recentConnection))
{ {
//+3 seconds for potential delay after getting connection
var cutOff = DateTime.Now.AddSeconds(-1 * proxyServer.ConnectionTimeOutSeconds + 3);
if (recentConnection.LastAccess > cutOff if (recentConnection.LastAccess > cutOff
&& recentConnection.TcpClient.IsGoodConnection()) && recentConnection.TcpClient.IsGoodConnection())
{ {
...@@ -490,8 +489,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -490,8 +489,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (queue.TryDequeue(out var connection)) if (queue.TryDequeue(out var connection))
{ {
if (!Server.EnableConnectionPool if (!Server.EnableConnectionPool || connection.LastAccess < cutOff)
|| connection.LastAccess < cutOff)
{ {
disposalBag.Add(connection); disposalBag.Add(connection);
} }
...@@ -508,8 +506,8 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -508,8 +506,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
await @lock.WaitAsync(); await @lock.WaitAsync();
//clear empty queues // clear empty queues
var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList(); var emptyKeys = cache.ToArray().Where(x => x.Value.Count == 0).Select(x => x.Key);
foreach (string key in emptyKeys) foreach (string key in emptyKeys)
{ {
cache.TryRemove(key, out _); cache.TryRemove(key, out _);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment