Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Do not release same connection twice
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Aug 16, 2021
1 parent 66d798d commit 2afe12d
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ internal TcpConnectionFactory(ProxyServer server)
bool prefetch, CancellationToken cancellationToken)
{
// deny connection to proxy end points to avoid infinite connection loop.
if (Server.ProxyEndPoints.Any(x => x.Port == remotePort)
if (Server.ProxyEndPoints.Any(x => x.Port == remotePort)
&& NetworkHelper.IsLocalIpAddress(remoteHostName))
{
throw new Exception($"A client is making HTTP request to one of the listening ports of this proxy {remoteHostName}:{remotePort}");
Expand Down Expand Up @@ -413,7 +413,7 @@ internal TcpConnectionFactory(ProxyServer server)
}

Task connectTask;

if (socks)
{
if (externalProxy!.ProxyDnsRequests)
Expand Down Expand Up @@ -629,6 +629,16 @@ internal TcpConnectionFactory(ProxyServer server)
/// <param name="close">Should we just close the connection instead of reusing?</param>
internal async Task Release(TcpServerConnection connection, bool close = false)
{
if (connection == null)
{
return;
}

if (disposalBag.Any(x => x == connection))
{
return;
}

if (close || connection.IsWinAuthenticated || !Server.EnableConnectionPool || connection.IsClosed)
{
disposalBag.Add(connection);
Expand All @@ -653,6 +663,11 @@ internal async Task Release(TcpServerConnection connection, bool close = false)
}
}

if (existingConnections.Any(x => x == connection))
{
break;
}

existingConnections.Enqueue(connection);
break;
}
Expand Down

0 comments on commit 2afe12d

Please sign in to comment.