@@ -71,7 +71,6 @@ internal string GetConnectionCacheKey(string remoteHostName, int remotePort,
71
71
cacheKeyBuilder . Append ( externalProxy != null ? $ "{ externalProxy . GetCacheKey ( ) } -" : string . Empty ) ;
72
72
73
73
return cacheKeyBuilder . ToString ( ) ;
74
-
75
74
}
76
75
77
76
/// <summary>
@@ -280,20 +279,6 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
280
279
retry :
281
280
try
282
281
{
283
- tcpClient = new TcpClient ( upStreamEndPoint )
284
- {
285
- NoDelay = proxyServer . NoDelay ,
286
- ReceiveTimeout = proxyServer . ConnectionTimeOutSeconds * 1000 ,
287
- SendTimeout = proxyServer . ConnectionTimeOutSeconds * 1000 ,
288
- LingerState = new LingerOption ( true , proxyServer . TcpTimeWaitSeconds )
289
- } ;
290
-
291
- // linux has a bug with socket reuse in .net core.
292
- if ( proxyServer . ReuseSocket && RunTime . IsWindows )
293
- {
294
- tcpClient . Client . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . ReuseAddress , true ) ;
295
- }
296
-
297
282
var hostname = useUpstreamProxy ? externalProxy . HostName : remoteHostName ;
298
283
var port = useUpstreamProxy ? externalProxy . Port : remotePort ;
299
284
@@ -312,6 +297,27 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
312
297
{
313
298
try
314
299
{
300
+ var ipAddress = ipAddresses [ i ] ;
301
+ if ( upStreamEndPoint == null )
302
+ {
303
+ tcpClient = new TcpClient ( ipAddress . AddressFamily ) ;
304
+ }
305
+ else
306
+ {
307
+ tcpClient = new TcpClient ( upStreamEndPoint ) ;
308
+ }
309
+
310
+ tcpClient . NoDelay = proxyServer . NoDelay ;
311
+ tcpClient . ReceiveTimeout = proxyServer . ConnectionTimeOutSeconds * 1000 ;
312
+ tcpClient . SendTimeout = proxyServer . ConnectionTimeOutSeconds * 1000 ;
313
+ tcpClient . LingerState = new LingerOption ( true , proxyServer . TcpTimeWaitSeconds ) ;
314
+
315
+ // linux has a bug with socket reuse in .net core.
316
+ if ( proxyServer . ReuseSocket && RunTime . IsWindows )
317
+ {
318
+ tcpClient . Client . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . ReuseAddress , true ) ;
319
+ }
320
+
315
321
await tcpClient . ConnectAsync ( ipAddresses [ i ] , port ) ;
316
322
break ;
317
323
}
0 commit comments