Commit 1fadb67c authored by justcoding121's avatar justcoding121

#184 move linger state experimentally to avoid object disposed exception on Close

parent 5faaa0b2
......@@ -58,7 +58,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
StreamReader?.Dispose();
TcpClient.LingerState = new LingerOption(true, 0);
TcpClient?.Close();
}
}
......
......@@ -133,6 +133,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
client.ReceiveTimeout = connectionTimeOutSeconds * 1000;
client.SendTimeout = connectionTimeOutSeconds * 1000;
client.LingerState = new LingerOption(true, 0);
return new TcpConnection
{
UpStreamHttpProxy = externalHttpProxy,
......
......@@ -583,13 +583,18 @@ namespace Titanium.Web.Proxy
//Other errors are discarded to keep proxy running
}
if (tcpClient != null)
{
Task.Run(async () =>
{
ClientConnectionCount++;
//This line is important!
//contributors please don't remove it without discussion
//It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//due to default TCP CLOSE_WAIT timeout for 4 minutes
tcpClient.LingerState = new LingerOption(true, 0);
try
{
if (endPoint.GetType() == typeof(TransparentProxyEndPoint))
......@@ -603,14 +608,8 @@ namespace Titanium.Web.Proxy
}
finally
{
//This line is important!
//contributors please don't remove it without discussion
//It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//due to default TCP CLOSE_WAIT timeout for 4 minutes
tcpClient.LingerState = new LingerOption(true, 0);
tcpClient?.Close();
ClientConnectionCount--;
tcpClient?.Close();
}
});
}
......
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