@@ -46,7 +46,6 @@ private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpCli
4646 try
4747 {
4848 string connectHostname = null ;
49-
5049 ConnectRequest connectRequest = null ;
5150
5251 //Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
@@ -297,7 +296,7 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
297296 string httpCmd = await clientStreamReader . ReadLineAsync ( ) ;
298297 if ( string . IsNullOrEmpty ( httpCmd ) )
299298 {
300- break ;
299+ return ;
301300 }
302301
303302 var args = new SessionEventArgs ( BufferSize , endPoint , ExceptionFunc )
@@ -364,7 +363,7 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
364363
365364 //send the response
366365 await clientStreamWriter . WriteResponseAsync ( args . WebSession . Response ) ;
367- break ;
366+ return ;
368367 }
369368
370369 if ( ! isTransparentEndPoint )
@@ -397,7 +396,7 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
397396
398397 if ( ! response . KeepAlive )
399398 {
400- break ;
399+ return ;
401400 }
402401
403402 continue ;
@@ -450,16 +449,22 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferSize,
450449 ( buffer , offset , count ) => { args . OnDataReceived ( buffer , offset , count ) ; } ,
451450 ExceptionFunc ) ;
452451
453- break ;
452+ return ;
454453 }
455454
456455 //construct the web request that we are going to issue on behalf of the client.
457456 await HandleHttpSessionRequestInternal ( connection , args ) ;
458457
458+ if ( args . WebSession . ServerConnection == null )
459+ {
460+ //server connection was closed
461+ return ;
462+ }
463+
459464 //if connection is closing exit
460465 if ( ! response . KeepAlive )
461466 {
462- break ;
467+ return ;
463468 }
464469 }
465470 catch ( Exception e ) when ( ! ( e is ProxyHttpException ) )
0 commit comments