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

Commit 2afe12d

Browse files
committed
Do not release same connection twice
1 parent 66d798d commit 2afe12d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Titanium.Web.Proxy/Network/TcpConnection/TcpConnectionFactory.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ internal Task<TcpServerConnection> GetServerConnection(ProxyServer proxyServer,
290290
bool prefetch, CancellationToken cancellationToken)
291291
{
292292
// deny connection to proxy end points to avoid infinite connection loop.
293-
if (Server.ProxyEndPoints.Any(x => x.Port == remotePort)
293+
if (Server.ProxyEndPoints.Any(x => x.Port == remotePort)
294294
&& NetworkHelper.IsLocalIpAddress(remoteHostName))
295295
{
296296
throw new Exception($"A client is making HTTP request to one of the listening ports of this proxy {remoteHostName}:{remotePort}");
@@ -413,7 +413,7 @@ internal Task<TcpServerConnection> GetServerConnection(ProxyServer proxyServer,
413413
}
414414

415415
Task connectTask;
416-
416+
417417
if (socks)
418418
{
419419
if (externalProxy!.ProxyDnsRequests)
@@ -629,6 +629,16 @@ internal Task<TcpServerConnection> GetServerConnection(ProxyServer proxyServer,
629629
/// <param name="close">Should we just close the connection instead of reusing?</param>
630630
internal async Task Release(TcpServerConnection connection, bool close = false)
631631
{
632+
if (connection == null)
633+
{
634+
return;
635+
}
636+
637+
if (disposalBag.Any(x => x == connection))
638+
{
639+
return;
640+
}
641+
632642
if (close || connection.IsWinAuthenticated || !Server.EnableConnectionPool || connection.IsClosed)
633643
{
634644
disposalBag.Add(connection);
@@ -653,6 +663,11 @@ internal async Task Release(TcpServerConnection connection, bool close = false)
653663
}
654664
}
655665

666+
if (existingConnections.Any(x => x == connection))
667+
{
668+
break;
669+
}
670+
656671
existingConnections.Enqueue(connection);
657672
break;
658673
}

0 commit comments

Comments
 (0)