From 341f6c4f302cca349104b55bc5cc817ef4da509e Mon Sep 17 00:00:00 2001 From: pan-wang Date: Wed, 18 Apr 2018 14:04:55 -0700 Subject: [PATCH] reset some timeout values to infinite if debugger is attached (#776) --- .../outofprocess/forwardinghandler.cpp | 14 ++++++++++---- .../RequestHandler/outofprocess/serverprocess.cxx | 10 +++++++++- .../RequestHandler/outofprocess/serverprocess.h | 9 +++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/AspNetCoreModuleV2/RequestHandler/outofprocess/forwardinghandler.cpp b/src/AspNetCoreModuleV2/RequestHandler/outofprocess/forwardinghandler.cpp index 4614b27d34..9b8c9466c8 100644 --- a/src/AspNetCoreModuleV2/RequestHandler/outofprocess/forwardinghandler.cpp +++ b/src/AspNetCoreModuleV2/RequestHandler/outofprocess/forwardinghandler.cpp @@ -1098,6 +1098,7 @@ FORWARDING_HANDLER::CreateWinHttpRequest( HRESULT hr = S_OK; PCWSTR pszVersion = NULL; PCSTR pszVerb; + DWORD dwTimeout = INFINITE; STACK_STRU(strVerb, 32); // @@ -1138,11 +1139,16 @@ FORWARDING_HANDLER::CreateWinHttpRequest( goto Finished; } + if (!pServerProcess->IsDebuggerAttached()) + { + dwTimeout = pProtocol->QueryTimeout(); + } + if (!WinHttpSetTimeouts(m_hRequest, - pProtocol->QueryTimeout(), - pProtocol->QueryTimeout(), - pProtocol->QueryTimeout(), - pProtocol->QueryTimeout())) + dwTimeout, //resolve timeout + dwTimeout, // connect timeout + dwTimeout, // send timeout + dwTimeout)) // receive timeout { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; diff --git a/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.cxx b/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.cxx index de309bf643..dc4aace72b 100644 --- a/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.cxx +++ b/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.cxx @@ -40,6 +40,7 @@ SERVER_PROCESS::Initialize( m_fAnonymousAuthEnabled = fAnonymousAuthEnabled; m_fWebsocketsEnabled = fWebsocketsEnabled; m_pProcessManager->ReferenceProcessManager(); + m_fDebuggerAttached = FALSE; if (FAILED(hr = m_ProcessPath.Copy(*pszProcessExePath)) || FAILED(hr = m_struLogFile.Copy(*pstruStdoutLogFile))|| @@ -719,6 +720,8 @@ SERVER_PROCESS::PostStartCheck( m_fReady = TRUE; Finished: + m_fDebuggerAttached = fDebuggerAttached; + if (FAILED(hr)) { if (m_pForwarderConnection != NULL) @@ -1277,7 +1280,12 @@ SERVER_PROCESS::SendSignal( goto Finished; } - if (WaitForSingleObject(m_hShutdownHandle, m_dwShutdownTimeLimitInMS) != WAIT_OBJECT_0) + // + // Reset the shutdown timeout if debugger is attached. + // Do it only for the case that debugger is attached during process creation + // as IsDebuggerIsAttached call is too heavy + // + if (WaitForSingleObject(m_hShutdownHandle, m_fDebuggerAttached ? INFINITE : m_dwShutdownTimeLimitInMS) != WAIT_OBJECT_0) { hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT); goto Finished; diff --git a/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.h b/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.h index ff76297a1c..e60454cac0 100644 --- a/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.h +++ b/src/AspNetCoreModuleV2/RequestHandler/outofprocess/serverprocess.h @@ -57,6 +57,14 @@ public: return m_fReady; } + BOOL + IsDebuggerAttached( + VOID + ) + { + return m_fDebuggerAttached; + } + VOID StopProcess( VOID @@ -230,6 +238,7 @@ private: BOOL m_fBasicAuthEnabled; BOOL m_fAnonymousAuthEnabled; BOOL m_fWebsocketsEnabled; + BOOL m_fDebuggerAttached; STTIMER m_Timer; SOCKET m_socket;