Commit 56de40a3 authored by justcoding121's avatar justcoding121

use try finally to release connection

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