Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
40c978d3
Unverified
Commit
40c978d3
authored
May 15, 2018
by
justcoding121
Committed by
GitHub
May 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #446 from justcoding121/master
Fix prefetch connection leak
parents
02ea4aec
d0f53206
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
33 deletions
+55
-33
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+21
-9
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+2
-2
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+19
-19
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+13
-3
No files found.
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
40c978d3
...
@@ -150,8 +150,12 @@ namespace Titanium.Web.Proxy
...
@@ -150,8 +150,12 @@ namespace Titanium.Web.Proxy
}
}
SslStream
sslStream
=
null
;
SslStream
sslStream
=
null
;
//don't pass cancellation token here
//it could cause floating server connections when client exits
prefetchConnectionTask
=
getServerConnection
(
connectArgs
,
true
,
prefetchConnectionTask
=
getServerConnection
(
connectArgs
,
true
,
null
,
false
,
cancellationToken
);
null
,
false
,
CancellationToken
.
None
);
try
try
{
{
sslStream
=
new
SslStream
(
clientStream
);
sslStream
=
new
SslStream
(
clientStream
);
...
@@ -250,7 +254,7 @@ namespace Titanium.Web.Proxy
...
@@ -250,7 +254,7 @@ namespace Titanium.Web.Proxy
{
{
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
}
}
calledRequestHandler
=
true
;
return
;
return
;
}
}
}
}
...
@@ -331,19 +335,27 @@ namespace Titanium.Web.Proxy
...
@@ -331,19 +335,27 @@ namespace Titanium.Web.Proxy
}
}
finally
finally
{
{
if
(!
calledRequestHandler
&&
prefetchConnectionTask
!=
null
)
{
TcpServerConnection
prefetchedConnection
=
null
;
try
{
prefetchedConnection
=
await
prefetchConnectionTask
;
}
finally
{
await
tcpConnectionFactory
.
Release
(
prefetchedConnection
,
closeServerConnection
);
}
}
clientStream
.
Dispose
();
clientStream
.
Dispose
();
if
(!
cancellationTokenSource
.
IsCancellationRequested
)
if
(!
cancellationTokenSource
.
IsCancellationRequested
)
{
{
cancellationTokenSource
.
Cancel
();
cancellationTokenSource
.
Cancel
();
}
}
if
(!
calledRequestHandler
&&
prefetchConnectionTask
!=
null
)
{
var
connection
=
await
prefetchConnectionTask
;
await
tcpConnectionFactory
.
Release
(
connection
,
closeServerConnection
);
}
}
}
}
}
}
}
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
40c978d3
...
@@ -815,12 +815,12 @@ namespace Titanium.Web.Proxy
...
@@ -815,12 +815,12 @@ namespace Titanium.Web.Proxy
.
RetryAsync
(
retries
,
.
RetryAsync
(
retries
,
onRetryAsync
:
async
(
ex
,
i
,
context
)
=>
onRetryAsync
:
async
(
ex
,
i
,
context
)
=>
{
{
if
(
context
.
ContainsKey
(
"connection"
)
)
if
(
context
[
"connection"
]
!=
null
)
{
{
//close connection on error
//close connection on error
var
connection
=
(
TcpServerConnection
)
context
[
"connection"
];
var
connection
=
(
TcpServerConnection
)
context
[
"connection"
];
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
context
.
Remove
(
"connection"
)
;
context
[
"connection"
]
=
null
;
}
}
});
});
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
40c978d3
...
@@ -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
)
...
@@ -204,21 +204,13 @@ namespace Titanium.Web.Proxy
...
@@ -204,21 +204,13 @@ namespace Titanium.Web.Proxy
connection
=
null
;
connection
=
null
;
}
}
var
contextData
=
new
Dictionary
<
string
,
object
>();
if
(
connection
!=
null
)
{
contextData
.
Add
(
"connection"
,
connection
);
}
//for connection pool retry fails until cache is exhausted
//for connection pool retry fails until cache is exhausted
await
retryPolicy
<
ServerConnectionException
>().
ExecuteAsync
(
async
(
context
)
=>
await
retryPolicy
<
ServerConnectionException
>().
ExecuteAsync
(
async
(
context
)
=>
{
{
connection
=
context
[
"connection"
]
as
TcpServerConnection
??
connection
=
context
.
ContainsKey
(
"connection"
)?
await
getServerConnection
(
args
,
false
,
(
TcpServerConnection
)
context
[
"connection"
]
clientConnection
.
NegotiatedApplicationProtocol
,
:
await
getServerConnection
(
args
,
false
,
false
,
cancellationToken
);
clientConnection
.
NegotiatedApplicationProtocol
,
false
,
cancellationToken
);
context
[
"connection"
]
=
connection
;
context
[
"connection"
]
=
connection
;
...
@@ -235,8 +227,7 @@ namespace Titanium.Web.Proxy
...
@@ -235,8 +227,7 @@ namespace Titanium.Web.Proxy
// construct the web request that we are going to issue on behalf of the client.
// construct the web request that we are going to issue on behalf of the client.
await
handleHttpSessionRequestInternal
(
connection
,
args
);
await
handleHttpSessionRequestInternal
(
connection
,
args
);
},
contextData
);
},
new
Dictionary
<
string
,
object
>
{
{
"connection"
,
connection
}
});
//user requested
//user requested
if
(
args
.
WebSession
.
CloseServerConnection
)
if
(
args
.
WebSession
.
CloseServerConnection
)
...
@@ -288,12 +279,21 @@ namespace Titanium.Web.Proxy
...
@@ -288,12 +279,21 @@ namespace Titanium.Web.Proxy
finally
finally
{
{
await
tcpConnectionFactory
.
Release
(
connection
,
await
tcpConnectionFactory
.
Release
(
connection
,
closeServerConnection
);
closeServerConnection
);
if
(
prefetchTask
!=
null
)
if
(
prefetchTask
!=
null
)
{
{
await
tcpConnectionFactory
.
Release
(
await
prefetchTask
,
TcpServerConnection
prefetchedConnection
=
null
;
closeServerConnection
);
try
{
prefetchedConnection
=
await
prefetchTask
;
}
finally
{
await
tcpConnectionFactory
.
Release
(
prefetchedConnection
,
closeServerConnection
);
}
}
}
}
}
}
}
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
40c978d3
...
@@ -63,9 +63,11 @@ namespace Titanium.Web.Proxy
...
@@ -63,9 +63,11 @@ namespace Titanium.Web.Proxy
if
(
endPoint
.
DecryptSsl
&&
args
.
DecryptSsl
)
if
(
endPoint
.
DecryptSsl
&&
args
.
DecryptSsl
)
{
{
//don't pass cancellation token here
//it could cause floating server connections when client exits
prefetchConnectionTask
=
tcpConnectionFactory
.
GetClient
(
httpsHostName
,
endPoint
.
Port
,
prefetchConnectionTask
=
tcpConnectionFactory
.
GetClient
(
httpsHostName
,
endPoint
.
Port
,
null
,
true
,
null
,
false
,
this
,
null
,
true
,
null
,
false
,
this
,
UpStreamEndPoint
,
UpStreamHttpsProxy
,
false
,
cancellationToken
);
UpStreamEndPoint
,
UpStreamHttpsProxy
,
false
,
CancellationToken
.
None
);
SslStream
sslStream
=
null
;
SslStream
sslStream
=
null
;
...
@@ -163,8 +165,16 @@ namespace Titanium.Web.Proxy
...
@@ -163,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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment