Commit 4fd1d6f1 authored by justcoding121's avatar justcoding121

properly release prefetch task

parent 79cdc5e9
......@@ -338,8 +338,16 @@ namespace Titanium.Web.Proxy
if (!calledRequestHandler
&& prefetchConnectionTask != null)
{
var connection = await prefetchConnectionTask;
await tcpConnectionFactory.Release(connection, closeServerConnection);
TcpServerConnection prefetchedConnection = null;
try
{
prefetchedConnection = await prefetchConnectionTask;
}
finally
{
await tcpConnectionFactory.Release(prefetchedConnection, closeServerConnection);
}
}
clientStream.Dispose();
......
......@@ -58,14 +58,14 @@ namespace Titanium.Web.Proxy
CancellationTokenSource cancellationTokenSource, string httpsConnectHostname, ConnectRequest connectRequest,
Task<TcpServerConnection> prefetchConnectionTask = null)
{
var cancellationToken = cancellationTokenSource.Token;
var prefetchTask = prefetchConnectionTask;
TcpServerConnection connection = null;
bool closeServerConnection = false;
try
{
var cancellationToken = cancellationTokenSource.Token;
// Loop through each subsequest request on this particular client connection
// (assuming HTTP connection is kept alive by client)
while (true)
......@@ -278,14 +278,23 @@ namespace Titanium.Web.Proxy
}
finally
{
await tcpConnectionFactory.Release(connection,
closeServerConnection);
if (prefetchTask != null)
{
await tcpConnectionFactory.Release(await prefetchTask,
closeServerConnection);
}
TcpServerConnection prefetchedConnection = null;
try
{
prefetchedConnection = await prefetchTask;
await tcpConnectionFactory.Release(connection,
closeServerConnection);
}
finally
{
await tcpConnectionFactory.Release(prefetchedConnection, closeServerConnection);
}
}
}
}
......
......@@ -165,8 +165,16 @@ namespace Titanium.Web.Proxy
if (!calledRequestHandler
&& prefetchConnectionTask != null)
{
var connection = await prefetchConnectionTask;
await tcpConnectionFactory.Release(connection, closeServerConnection);
TcpServerConnection prefetchedConnection = null;
try
{
prefetchedConnection = await prefetchConnectionTask;
}
finally
{
await tcpConnectionFactory.Release(prefetchedConnection, closeServerConnection);
}
}
clientStream.Dispose();
......
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