From f13a49bd2a35c7680db410369e96bf68a5c9c3c9 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Tue, 13 Nov 2018 16:57:15 -0800 Subject: [PATCH 1/2] Fix websocket disconnect issue --- .../AspNetCore/src/websockethandler.cxx | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx b/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx index 7adc14c915..afa0b950e1 100644 --- a/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx +++ b/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx @@ -266,6 +266,7 @@ Routine Description: HRESULT hr = S_OK; //DWORD dwBuffSize = RECEIVE_BUFFER_SIZE; + *fHandleCreated = FALSE; _pHandler = pHandler; EnterCriticalSection(&_RequestLock); @@ -1145,21 +1146,34 @@ Arguments: _fCleanupInProgress = TRUE; _fIndicateCompletionToIis = TRUE; - // - // We need cancel IO for fast error handling - // Reivist the code once CanelOutstandingIO api is available - // - /*if (_pWebSocketContext != NULL) + + if (reason == ClientDisconnect || reason == ServerStateUnavailable) { - _pWebSocketContext->CancelOutstandingIO(); - }*/ - _pHttpContext->CancelIo(); + // + // Calling shutdown to notify the backend about disonnect + // + WINHTTP_HELPER::sm_pfnWinHttpWebSocketShutdown( + _hWebSocketRequest, + 1011, // indicate that a server is terminating the connection because it encountered + // an unexpected condition that prevent it from fulfilling the request + NULL, // Reason + 0); // length og Reason + } + + if (reason == ServerDisconnect || reason == ServerStateUnavailable) + { + _pHttpContext->CancelIo(); + // + // CancelIo sometime may not be able to cannel pending websocket IO + // ResetConnection to force IISWebsocket module to release the pipeline + // + _pHttpContext->GetResponse()->ResetConnection(); + } // // Don't close the handle here, // as it trigger a WinHttp callback and let IIS pipeline continue // Handle should be closed only in IndicateCompletionToIIS - IndicateCompletionToIIS(); Finished: if (fLocked) { From 1858527fb0d53b6bd0d6dcbe252e5ec710ca0afc Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 14 Nov 2018 09:32:16 -0800 Subject: [PATCH 2/2] Feedback --- .../AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx b/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx index afa0b950e1..1816154a0c 100644 --- a/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx +++ b/src/IISIntegration/src/AspNetCoreModuleV1/AspNetCore/src/websockethandler.cxx @@ -1154,8 +1154,8 @@ Arguments: // WINHTTP_HELPER::sm_pfnWinHttpWebSocketShutdown( _hWebSocketRequest, - 1011, // indicate that a server is terminating the connection because it encountered - // an unexpected condition that prevent it from fulfilling the request + WINHTTP_WEB_SOCKET_SERVER_ERROR_CLOSE_STATUS, // indicate that a server is terminating the connection because it encountered + // an unexpected condition that prevent it from fulfilling the request NULL, // Reason 0); // length og Reason }