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

Commit 87f808c

Browse files
committed
fixing the AV for graceful shutdown on Win7, set forwardWindowsAuthToken default to true and other minor issues
1 parent 839437e commit 87f808c

File tree

5 files changed

+44
-45
lines changed

5 files changed

+44
-45
lines changed

src/AspNetCore/Inc/applicationmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class APPLICATION_MANAGER
141141
<li> Enable logging the application process' stdout messages </li> \
142142
<li> Attach a debugger to the application process and inspect </li></ul></fieldset> \
143143
<fieldset><h4> For more information visit: \
144-
<a href=\"http://go.microsoft.com/fwlink/?linkid=808681\" <cite> http://go.microsoft.com/fwlink/?LinkID=808681 </cite></a></h4> \
144+
<a href=\"https://go.microsoft.com/fwlink/?linkid=808681\" <cite> https://go.microsoft.com/fwlink/?LinkID=808681 </cite></a></h4> \
145145
</fieldset> \
146146
</div> \
147147
</div></body></html>")

src/AspNetCore/Inc/serverprocess.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ class SERVER_PROCESS
237237
DWORD m_dwProcessId;
238238
DWORD m_dwListeningProcessId;
239239
STRA m_straGuid;
240-
HANDLE m_CancelEvent;
241240

242241
//
243242
// m_hProcessHandle is the handle to process this object creates.

src/AspNetCore/Src/processmanager.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ PROCESS_MANAGER::GetProcess(
232232
goto Finished;
233233
}
234234

235-
this->ReferenceProcessManager();
236235
hr = m_ppServerProcessList[dwProcessIndex]->Initialize(
237236
this,
238237
pConfig->QueryProcessPath(),

src/AspNetCore/Src/serverprocess.cxx

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ SERVER_PROCESS::Initialize(
2929
m_dwShutdownTimeLimitInMS = dwShtudownTimeLimitInMS;
3030
m_fStdoutLogEnabled = fStdoutLogEnabled;
3131

32+
m_pProcessManager->ReferenceProcessManager();
33+
3234
hr = m_ProcessPath.Copy(*pszProcessExePath);
3335
if (FAILED(hr))
3436
{
@@ -1208,7 +1210,7 @@ SERVER_PROCESS::CheckIfServerIsUp(
12081210
return hr;
12091211
}
12101212

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

@@ -1217,62 +1219,69 @@ SERVER_PROCESS::SendSignal(
12171219
VOID
12181220
)
12191221
{
1220-
HANDLE hProc;
1222+
HANDLE hProc = INVALID_HANDLE_VALUE;
12211223
BOOL fIsSuccess = FALSE;
12221224
LPCWSTR apsz[1];
12231225
STACK_STRU(strEventMsg, 256);
12241226

12251227
hProc = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, FALSE, m_dwProcessId);
12261228
if (hProc != INVALID_HANDLE_VALUE)
12271229
{
1228-
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
1230+
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
12291231

12301232
if (!fIsSuccess)
12311233
{
12321234
if (AttachConsole(m_dwProcessId))
12331235
{
1234-
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
1236+
fIsSuccess = GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessId);
12351237
FreeConsole();
1236-
CloseHandle(m_hProcessHandle);
1237-
m_hProcessHandle = INVALID_HANDLE_VALUE;
1238-
}
1239-
1240-
if (!fIsSuccess)
1241-
{
1242-
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
1243-
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
1244-
m_dwProcessId )))
1245-
{
1246-
apsz[0] = strEventMsg.QueryStr();
1247-
// log a warning for ungraceful shutdown
1248-
if (FORWARDING_HANDLER::QueryEventLog() != NULL)
1249-
{
1250-
ReportEventW(FORWARDING_HANDLER::QueryEventLog(),
1251-
EVENTLOG_INFORMATION_TYPE,
1252-
0,
1253-
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
1254-
NULL,
1255-
1,
1256-
0,
1257-
apsz,
1258-
NULL);
1259-
}
1260-
}
12611238
}
1239+
}
1240+
}
1241+
1242+
if (!fIsSuccess || (WaitForSingleObject(hProc, m_dwShutdownTimeLimitInMS) != WAIT_OBJECT_0))
1243+
{
1244+
//Backend process will be terminated, remove the waitcallback
1245+
if (m_hProcessWaitHandle != NULL)
1246+
{
1247+
UnregisterWait(m_hProcessWaitHandle);
1248+
m_hProcessWaitHandle = NULL;
12621249
}
12631250

1264-
if (!fIsSuccess || (WaitForSingleObject(hProc, m_dwShutdownTimeLimitInMS) != WAIT_OBJECT_0))
1251+
// cannot gracefully shutdown or timeout, terminate the process
1252+
TerminateProcess(m_hProcessHandle, 0);
1253+
1254+
// log a warning for ungraceful shutdown
1255+
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
1256+
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG,
1257+
m_dwProcessId)))
12651258
{
1266-
// cannot gracefule shutdown or timeout
1267-
// terminate the process
1268-
TerminateProcess(m_hProcessHandle, 0);
1259+
apsz[0] = strEventMsg.QueryStr();
1260+
if (FORWARDING_HANDLER::QueryEventLog() != NULL)
1261+
{
1262+
ReportEventW(FORWARDING_HANDLER::QueryEventLog(),
1263+
EVENTLOG_WARNING_TYPE,
1264+
0,
1265+
ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE,
1266+
NULL,
1267+
1,
1268+
0,
1269+
apsz,
1270+
NULL);
1271+
}
12691272
}
12701273
}
1274+
12711275
if (hProc != INVALID_HANDLE_VALUE)
12721276
{
12731277
CloseHandle(hProc);
12741278
hProc = INVALID_HANDLE_VALUE;
12751279
}
1280+
if (m_hProcessHandle != INVALID_HANDLE_VALUE)
1281+
{
1282+
CloseHandle(m_hProcessHandle);
1283+
m_hProcessHandle = INVALID_HANDLE_VALUE;
1284+
}
12761285
}
12771286

12781287
//
@@ -1640,7 +1649,6 @@ SERVER_PROCESS::StopAllProcessesInJobObject(
16401649

16411650
SERVER_PROCESS::SERVER_PROCESS() :
16421651
m_cRefs( 1 ),
1643-
m_CancelEvent( NULL ),
16441652
m_hProcessHandle( NULL ),
16451653
m_hProcessWaitHandle( NULL ),
16461654
m_dwProcessId( 0 ),
@@ -1681,13 +1689,6 @@ SERVER_PROCESS::~SERVER_PROCESS()
16811689
m_hProcessWaitHandle = NULL;
16821690
}
16831691

1684-
if( m_CancelEvent != NULL )
1685-
{
1686-
SetEvent( m_CancelEvent );
1687-
CloseHandle( m_CancelEvent );
1688-
m_CancelEvent = NULL;
1689-
}
1690-
16911692
for(INT i=0;i<MAX_ACTIVE_CHILD_PROCESSES;++i)
16921693
{
16931694
if(m_hChildProcessWaitHandles[i] != NULL)

src/AspNetCore/aspnetcore_schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<attribute name="stdoutLogEnabled" type="bool" defaultValue="false" />
2424
<attribute name="stdoutLogFile" type="string" defaultValue=".\aspnetcore-stdout" expanded="true"/>
2525
<attribute name="processesPerApplication" type="uint" defaultValue="1" validationType="integerRange" validationParameter="1,100"/>
26-
<attribute name="forwardWindowsAuthToken" type="bool" defaultValue="false" />
26+
<attribute name="forwardWindowsAuthToken" type="bool" defaultValue="true" />
2727
<attribute name="disableStartUpErrorPage" type="bool" defaultValue="false" />
2828
<element name="recycleOnFileChange">
2929
<collection addElement="file" clearElement="clear">

0 commit comments

Comments
 (0)