Commit 4fd1d6f1 authored by justcoding121's avatar justcoding121

properly release prefetch task

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