Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

fixing the AV for graceful shutdown on Win7, set forwardWindowsAuthTo… #59

Merged
merged 2 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AspNetCore/Inc/applicationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class APPLICATION_MANAGER
<li> Enable logging the application process' stdout messages </li> \
<li> Attach a debugger to the application process and inspect </li></ul></fieldset> \
<fieldset><h4> For more information visit: \
<a href=\"http://go.microsoft.com/fwlink/?linkid=808681\" <cite> http://go.microsoft.com/fwlink/?LinkID=808681 </cite></a></h4> \
<a href=\"https://go.microsoft.com/fwlink/?linkid=808681\"> <cite> https://go.microsoft.com/fwlink/?LinkID=808681 </cite></a></h4> \
</fieldset> \
</div> \
</div></body></html>")
Expand Down
1 change: 0 additions & 1 deletion src/AspNetCore/Inc/serverprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ class SERVER_PROCESS
DWORD m_dwProcessId;
DWORD m_dwListeningProcessId;
STRA m_straGuid;
HANDLE m_CancelEvent;

//
// m_hProcessHandle is the handle to process this object creates.
Expand Down
1 change: 0 additions & 1 deletion src/AspNetCore/Src/processmanager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ PROCESS_MANAGER::GetProcess(
goto Finished;
}

this->ReferenceProcessManager();
hr = m_ppServerProcessList[dwProcessIndex]->Initialize(
this,
pConfig->QueryProcessPath(),
Expand Down
83 changes: 42 additions & 41 deletions src/AspNetCore/Src/serverprocess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ SERVER_PROCESS::Initialize(
m_dwShutdownTimeLimitInMS = dwShtudownTimeLimitInMS;
m_fStdoutLogEnabled = fStdoutLogEnabled;

m_pProcessManager->ReferenceProcessManager();

hr = m_ProcessPath.Copy(*pszProcessExePath);
if (FAILED(hr))
{
Expand Down Expand Up @@ -1208,7 +1210,7 @@ SERVER_PROCESS::CheckIfServerIsUp(
return hr;
}

// send ctrl-c signnal to the process to let it graceful shutdown
// send ctrl-c signnal to the process to let it gracefully shutdown
// if the process cannot shutdown within given time, terminate it
// todo: allow user to config this shutdown timeout

Expand All @@ -1217,62 +1219,69 @@ SERVER_PROCESS::SendSignal(
VOID
)
{
HANDLE hProc;
HANDLE hProc = INVALID_HANDLE_VALUE;
BOOL fIsSuccess = FALSE;
LPCWSTR apsz[1];
STACK_STRU(strEventMsg, 256);

hProc = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, FALSE, m_dwProcessId);
if (hProc != INVALID_HANDLE_VALUE)
{
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);

if (!fIsSuccess)
{
if (AttachConsole(m_dwProcessId))
{
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
FreeConsole();
CloseHandle(m_hProcessHandle);
m_hProcessHandle = INVALID_HANDLE_VALUE;
}

if (!fIsSuccess)
{
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
m_dwProcessId )))
{
apsz[0] = strEventMsg.QueryStr();
// log a warning for ungraceful shutdown
if (FORWARDING_HANDLER::QueryEventLog() != NULL)
{
ReportEventW(FORWARDING_HANDLER::QueryEventLog(),
EVENTLOG_INFORMATION_TYPE,
0,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
NULL,
1,
0,
apsz,
NULL);
}
}
}
}
}

if (!fIsSuccess || (WaitForSingleObject(hProc, m_dwShutdownTimeLimitInMS) != WAIT_OBJECT_0))
{
//Backend process will be terminated, remove the waitcallback
if (m_hProcessWaitHandle != NULL)
{
UnregisterWait(m_hProcessWaitHandle);
m_hProcessWaitHandle = NULL;
}

if (!fIsSuccess || (WaitForSingleObject(hProc, m_dwShutdownTimeLimitInMS) != WAIT_OBJECT_0))
// cannot gracefully shutdown or timeout, terminate the process
TerminateProcess(m_hProcessHandle, 0);

// log a warning for ungraceful shutdown
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
m_dwProcessId)))
{
// cannot gracefule shutdown or timeout
// terminate the process
TerminateProcess(m_hProcessHandle, 0);
apsz[0] = strEventMsg.QueryStr();
if (FORWARDING_HANDLER::QueryEventLog() != NULL)
{
ReportEventW(FORWARDING_HANDLER::QueryEventLog(),
EVENTLOG_WARNING_TYPE,
0,
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
NULL,
1,
0,
apsz,
NULL);
}
}
}

if (hProc != INVALID_HANDLE_VALUE)
{
CloseHandle(hProc);
hProc = INVALID_HANDLE_VALUE;
}
if (m_hProcessHandle != INVALID_HANDLE_VALUE)
{
CloseHandle(m_hProcessHandle);
m_hProcessHandle = INVALID_HANDLE_VALUE;
}
}

//
Expand Down Expand Up @@ -1640,7 +1649,6 @@ SERVER_PROCESS::StopAllProcessesInJobObject(

SERVER_PROCESS::SERVER_PROCESS() :
m_cRefs( 1 ),
m_CancelEvent( NULL ),
m_hProcessHandle( NULL ),
m_hProcessWaitHandle( NULL ),
m_dwProcessId( 0 ),
Expand Down Expand Up @@ -1681,13 +1689,6 @@ SERVER_PROCESS::~SERVER_PROCESS()
m_hProcessWaitHandle = NULL;
}

if( m_CancelEvent != NULL )
{
SetEvent( m_CancelEvent );
CloseHandle( m_CancelEvent );
m_CancelEvent = NULL;
}

for(INT i=0;i<MAX_ACTIVE_CHILD_PROCESSES;++i)
{
if(m_hChildProcessWaitHandles[i] != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/AspNetCore/aspnetcore_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<attribute name="stdoutLogEnabled" type="bool" defaultValue="false" />
<attribute name="stdoutLogFile" type="string" defaultValue=".\aspnetcore-stdout" expanded="true"/>
<attribute name="processesPerApplication" type="uint" defaultValue="1" validationType="integerRange" validationParameter="1,100"/>
<attribute name="forwardWindowsAuthToken" type="bool" defaultValue="false" />
<attribute name="forwardWindowsAuthToken" type="bool" defaultValue="true" />
<attribute name="disableStartUpErrorPage" type="bool" defaultValue="false" />
<element name="recycleOnFileChange">
<collection addElement="file" clearElement="clear">
Expand Down