Commit 56de40a3 authored by justcoding121's avatar justcoding121

use try finally to release connection

parent abc21b87
......@@ -212,6 +212,8 @@ namespace Titanium.Web.Proxy
var connection = await getServerConnection(connectArgs, true,
null, cancellationToken);
try
{
if (isClientHello)
{
int available = clientStream.Available;
......@@ -242,8 +244,11 @@ namespace Titanium.Web.Proxy
(buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); },
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); },
connectArgs.CancellationTokenSource, ExceptionFunc);
}
finally
{
await tcpConnectionFactory.Release(connection, true);
}
return;
}
}
......@@ -276,7 +281,8 @@ namespace Titanium.Web.Proxy
// create new connection
var connection = await getServerConnection(connectArgs, true, SslExtensions.Http2ProtocolAsList,
cancellationToken);
try
{
await connection.StreamWriter.WriteLineAsync("PRI * HTTP/2.0", cancellationToken);
await connection.StreamWriter.WriteLineAsync(cancellationToken);
await connection.StreamWriter.WriteLineAsync("SM", cancellationToken);
......@@ -288,9 +294,13 @@ namespace Titanium.Web.Proxy
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); },
connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc);
#endif
}
finally
{
await tcpConnectionFactory.Release(connection, true);
}
}
}
calledRequestHandler = true;
// Now create the request
await handleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
......
......@@ -98,7 +98,8 @@ namespace Titanium.Web.Proxy
null, false, null,
true, this, UpStreamEndPoint, UpStreamHttpsProxy, cancellationToken);
try
{
var serverStream = connection.Stream;
int available = clientStream.Available;
......@@ -122,10 +123,13 @@ namespace Titanium.Web.Proxy
await TcpHelper.SendRaw(clientStream, serverStream, BufferPool, BufferSize,
null, null, cancellationTokenSource, ExceptionFunc);
}
finally
{
await tcpConnectionFactory.Release(connection, true);
return;
}
return;
}
}
calledRequestHandler = true;
......
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