@@ -47,7 +47,7 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
47
47
{
48
48
string connectHostname = null ;
49
49
TunnelConnectSessionEventArgs connectArgs = null ;
50
-
50
+
51
51
52
52
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
53
53
if ( await HttpHelper . IsConnectMethod ( clientStream ) == 1 )
@@ -154,11 +154,17 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
154
154
155
155
if ( EnableTcpServerConnectionPrefetch )
156
156
{
157
- //don't pass cancellation token here
158
- //it could cause floating server connections when client exits
159
- prefetchConnectionTask = tcpConnectionFactory . GetServerConnection ( this , connectArgs ,
160
- isConnect : true , applicationProtocols : null , noCache : false ,
161
- cancellationToken : CancellationToken . None ) ;
157
+ //make sure the host can be resolved before creating the prefetch task
158
+ var ipAddresses = await Dns . GetHostAddressesAsync ( connectArgs . HttpClient . Request . RequestUri . Host ) ;
159
+
160
+ if ( ipAddresses != null && ipAddresses . Length > 0 )
161
+ {
162
+ //don't pass cancellation token here
163
+ //it could cause floating server connections when client exits
164
+ prefetchConnectionTask = tcpConnectionFactory . GetServerConnection ( this , connectArgs ,
165
+ isConnect : true , applicationProtocols : null , noCache : false ,
166
+ cancellationToken : CancellationToken . None ) ;
167
+ }
162
168
}
163
169
164
170
X509Certificate2 certificate = null ;
0 commit comments