summaryrefslogtreecommitdiff
path: root/buildscripts
diff options
context:
space:
mode:
authorRobert Guo <robertguo@me.com>2016-08-01 18:20:13 -0400
committerRobert Guo <robertguo@me.com>2016-08-25 12:12:01 -0400
commit4a7dd24ab3705ceaf752e714b92148032e20bd5d (patch)
treea3cd810cc4bef0157527e9a1d95df8cf52d7c049 /buildscripts
parentf84b0bbdb5ba8cb4c44f84ec99b5ffcf6078e5a1 (diff)
downloadmongo-4a7dd24ab3705ceaf752e714b92148032e20bd5d.tar.gz
SERVER-25358 resmoke should shutdown mongod cleanly on Windows
(cherry picked from commit b13bac6c1bbd11a1cf8015e3fd77b686cec1d290)
Diffstat (limited to 'buildscripts')
-rw-r--r--buildscripts/resmokelib/core/process.py38
1 files changed, 34 insertions, 4 deletions
diff --git a/buildscripts/resmokelib/core/process.py b/buildscripts/resmokelib/core/process.py
index f54b0f0a640..b8efa8af25a 100644
--- a/buildscripts/resmokelib/core/process.py
+++ b/buildscripts/resmokelib/core/process.py
@@ -56,6 +56,7 @@ _POPEN_LOCK = threading.Lock()
if sys.platform == "win32":
import win32api
import win32con
+ import win32event
import win32job
import win32process
import winerror
@@ -163,11 +164,40 @@ class Process(object):
raise
def stop(self):
- """
- Terminates the process.
- """
-
+ """Terminate the process."""
if sys.platform == "win32":
+
+ # Attempt to cleanly shutdown mongod.
+ if len(self.args) > 0 and self.args[0].find("mongod") != -1:
+ mongo_signal_handle = None
+ try:
+ mongo_signal_handle = win32event.OpenEvent(
+ win32event.EVENT_MODIFY_STATE, False, "Global\\Mongo_" +
+ str(self._process.pid))
+
+ if not mongo_signal_handle:
+ # The process has already died.
+ return
+ win32event.SetEvent(mongo_signal_handle)
+ # Wait 60 seconds for the program to exit.
+ status = win32event.WaitForSingleObject(
+ self._process._handle, 60 * 1000)
+ if status == win32event.WAIT_OBJECT_0:
+ return
+ except win32process.error as err:
+ # ERROR_FILE_NOT_FOUND (winerror=2)
+ # ERROR_ACCESS_DENIED (winerror=5)
+ # ERROR_INVALID_HANDLE (winerror=6)
+ # One of the above errors is received if the process has
+ # already died.
+ if err[0] not in (2, 5, 6):
+ raise
+ finally:
+ win32api.CloseHandle(mongo_signal_handle)
+
+ print "Failed to cleanly exit the program, calling TerminateProcess() on PID: " +\
+ str(self._process.pid)
+
# Adapted from implementation of Popen.terminate() in subprocess.py of Python 2.7
# because earlier versions do not catch exceptions.
try: