提交 8c5b7fd2 编写于 作者: A Alexis Campailla

fork: let child terminate without requiring signal from parent

The quasi-fork child was waiting for an explicit signal from the parent
before terminating. This synchronization step is unnecessary, and
it makes the child hang if the parent terminates for any reason
while the fork operation is in progress.
In that scenario, and consistently with the Posix version, the child
now completes the fork operation and terminates freely when done.

This fixes https://github.com/MSOpenTech/redis/issues/228
上级 92abb126
......@@ -177,7 +177,6 @@ struct QForkControl {
HANDLE forkedProcessReady;
HANDLE operationComplete;
HANDLE operationFailed;
HANDLE terminateForkedProcess;
// global data pointers to be passed to the forked process
QForkBeginInfo globalData;
......@@ -267,8 +266,6 @@ BOOL QForkSlaveInit(HANDLE QForkConrolMemoryMapHandle, DWORD ParentProcessID) {
g_pQForkControl->operationComplete = dupOperationComplete;
SmartHandle dupOperationFailed(shParent,sfvMasterQForkControl->operationFailed);
g_pQForkControl->operationFailed = dupOperationFailed;
SmartHandle dupTerminateProcess(shParent,sfvMasterQForkControl->terminateForkedProcess);
g_pQForkControl->terminateForkedProcess = dupTerminateProcess;
// create section handle on MM file
SIZE_T mmSize = g_pQForkControl->availableBlocksInHeap * cAllocationGranularity;
......@@ -333,9 +330,6 @@ BOOL QForkSlaveInit(HANDLE QForkConrolMemoryMapHandle, DWORD ParentProcessID) {
// let parent know we are done
SetEvent(g_pQForkControl->operationComplete);
// parent will notify us when to quit
WaitForSingleObject(g_pQForkControl->terminateForkedProcess, INFINITE);
g_pQForkControl = NULL;
return TRUE;
}
......@@ -599,13 +593,6 @@ BOOL QForkMasterInit( __int64 maxheapBytes ) {
system_category(),
"CreateEvent failed.");
}
g_pQForkControl->terminateForkedProcess = CreateEvent(NULL,TRUE,FALSE,NULL);
if (g_pQForkControl->terminateForkedProcess == NULL) {
throw std::system_error(
GetLastError(),
system_category(),
"CreateEvent failed.");
}
return TRUE;
}
......@@ -791,10 +778,6 @@ BOOL QForkShutdown() {
CloseHandle(g_pQForkControl->operationFailed);
g_pQForkControl->operationFailed = NULL;
}
if (g_pQForkControl->terminateForkedProcess != NULL) {
CloseHandle(g_pQForkControl->terminateForkedProcess);
g_pQForkControl->terminateForkedProcess = NULL;
}
if (g_pQForkControl->heapMemoryMap != NULL) {
CloseHandle(g_pQForkControl->heapMemoryMap);
g_pQForkControl->heapMemoryMap = NULL;
......@@ -879,12 +862,6 @@ void CreateChildProcess(PROCESS_INFORMATION *pi, char* logfile, DWORD dwCreation
system_category(),
"BeginForkOperation: ResetEvent() failed.");
}
if (ResetEvent(g_pQForkControl->terminateForkedProcess) == FALSE) {
throw std::system_error(
GetLastError(),
system_category(),
"BeginForkOperation: ResetEvent() failed.");
}
// Launch the "forked" process
char fileName[MAX_PATH];
......@@ -1153,7 +1130,6 @@ void RejoinCOWPages(HANDLE mmHandle, byte* mmStart, size_t mmSize) {
BOOL EndForkOperation(int * pExitCode) {
try {
SetEvent(g_pQForkControl->terminateForkedProcess);
if( g_hForkedProcess != 0 )
{
if (WaitForSingleObject(g_hForkedProcess, cDeadForkWait) == WAIT_TIMEOUT) {
......@@ -1191,12 +1167,6 @@ BOOL EndForkOperation(int * pExitCode) {
system_category(),
"EndForkOperation: ResetEvent() failed.");
}
if (ResetEvent(g_pQForkControl->terminateForkedProcess) == FALSE) {
throw std::system_error(
GetLastError(),
system_category(),
"EndForkOperation: ResetEvent() failed.");
}
// move local changes back into memory mapped views for next fork operation
RejoinCOWPages(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册