diff options
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp index b00a250cbdb..6aa2820bde6 100644 --- a/src/mongo/shell/shell_utils_launcher.cpp +++ b/src/mongo/shell/shell_utils_launcher.cpp @@ -512,10 +512,15 @@ bool wait_for_pid(ProcessId pid, bool block = true, int* exit_code = NULL) { verify(registry._handles.count(pid)); HANDLE h = registry._handles[pid]; - if (block) { - if (WaitForSingleObject(h, INFINITE)) { - log() << "WaitForSingleObject failed: " << errnoWithDescription(); - } + // wait until the process object is signaled before getting its + // exit code. do this even when block is false to ensure that all + // file handles open in the process have been closed. + + DWORD ret = WaitForSingleObject(h, (block ? INFINITE : 0)); + if (ret == WAIT_TIMEOUT) { + return false; + } else if (ret != WAIT_OBJECT_0) { + log() << "wait_for_pid: WaitForSingleObject failed: " << errnoWithDescription(); } DWORD tmp; |