summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2016-09-15 13:00:00 -0400
committerMathias Stearn <redbeard0531@gmail.com>2016-11-02 17:15:20 -0400
commit7a7d6144bb18878895087d775ffefd5cfdbb0d65 (patch)
tree42b94257ad0e73cf9683c615256795e6d22428a7
parent38516f5c5548b5f625d60750279928df5ff953c9 (diff)
downloadmongo-7a7d6144bb18878895087d775ffefd5cfdbb0d65.tar.gz
SERVER-25777 When stopping a spawned process, MongoDB shell will now abort after implicitly falling back to SIGKILL after timeout.
(cherry picked from commit 0b879b315473bb2d0a296a782a1dc8cf7fac8e20)
-rw-r--r--jstests/replsets/apply_ops_wc.js4
-rw-r--r--jstests/replsets/stepdown_killop.js1
-rw-r--r--src/mongo/shell/dbshell.cpp3
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp39
-rw-r--r--src/mongo/shell/shell_utils_launcher.h2
5 files changed, 24 insertions, 25 deletions
diff --git a/jstests/replsets/apply_ops_wc.js b/jstests/replsets/apply_ops_wc.js
index 5783d515c37..6e3467f5906 100644
--- a/jstests/replsets/apply_ops_wc.js
+++ b/jstests/replsets/apply_ops_wc.js
@@ -128,4 +128,8 @@
majorityWriteConcerns.forEach(testMajorityWriteConcerns);
+ // Allow clean shutdown
+ secondaries[0].getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'});
+ secondaries[1].getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'});
+
})();
diff --git a/jstests/replsets/stepdown_killop.js b/jstests/replsets/stepdown_killop.js
index c5fc593239b..5c0e0ffae91 100644
--- a/jstests/replsets/stepdown_killop.js
+++ b/jstests/replsets/stepdown_killop.js
@@ -100,4 +100,5 @@
assert.writeOK(primary.getDB(name).foo.remove({}));
exitCode = writer();
assert.eq(0, exitCode);
+ secondary.getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'});
})();
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index c064c292e83..609bbabf1b4 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -727,6 +727,9 @@ int _main(int argc, char* argv[], char** envp) {
cout << "failed to load: " << shellGlobalParams.files[i] << endl;
return -3;
}
+ if (mongo::shell_utils::KillMongoProgramInstances() != EXIT_SUCCESS) {
+ return -3;
+ }
}
if (shellGlobalParams.files.size() == 0 && shellGlobalParams.script.empty())
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index 4d5dcffc357..81793143ec0 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -743,7 +743,6 @@ inline void kill_wrapper(ProcessId pid, int sig, int port, const BSONObj& opt) {
int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) {
ProcessId pid;
- int exitCode = 0;
if (port > 0) {
if (!registry.isPortRegistered(port)) {
log() << "No db started on port: " << port;
@@ -756,32 +755,18 @@ int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) {
kill_wrapper(pid, signal, port, opt);
- bool processTerminated = false;
- bool killSignalSent = (signal == SIGKILL);
- for (int i = 0; i < 1300; ++i) {
- if (i == 600) {
- log() << "process on port " << port << ", with pid " << pid
- << " not terminated, sending sigkill";
- kill_wrapper(pid, SIGKILL, port, opt);
- killSignalSent = true;
- }
- processTerminated = wait_for_pid(pid, false, &exitCode);
- if (processTerminated) {
- break;
- }
- sleepmillis(100);
- }
- if (!processTerminated) {
- severe() << "failed to terminate process on port " << port << ", with pid " << pid;
- invariant(false);
- }
-
+ int exitCode = EXIT_FAILURE;
+ bool processTerminated = wait_for_pid(pid, true, &exitCode);
registry.deleteProgram(pid);
- if (killSignalSent) {
+ if (signal == SIGKILL) {
sleepmillis(4000); // allow operating system to reclaim resources
}
+ if (!processTerminated) {
+ warning() << "process " << pid << " failed to terminate.";
+ return EXIT_FAILURE;
+ }
return exitCode;
}
@@ -837,12 +822,18 @@ BSONObj StopMongoProgramByPid(const BSONObj& a, void* data) {
return BSON("" << (double)code);
}
-void KillMongoProgramInstances() {
+int KillMongoProgramInstances() {
vector<ProcessId> pids;
registry.getRegisteredPids(pids);
+ int returnCode = EXIT_SUCCESS;
for (auto&& pid : pids) {
- killDb(0, pid, SIGTERM);
+ int port = registry.portForPid(pid);
+ int code = killDb(port != -1 ? port : 0, pid, SIGTERM);
+ if (code != EXIT_SUCCESS) {
+ returnCode = code;
+ }
}
+ return returnCode;
}
MongoProgramScope::~MongoProgramScope() {
diff --git a/src/mongo/shell/shell_utils_launcher.h b/src/mongo/shell/shell_utils_launcher.h
index fd58c1bd614..dcf57c4451d 100644
--- a/src/mongo/shell/shell_utils_launcher.h
+++ b/src/mongo/shell/shell_utils_launcher.h
@@ -52,7 +52,7 @@ struct MongoProgramScope {
MongoProgramScope() {} // Avoid 'unused variable' warning.
~MongoProgramScope();
};
-void KillMongoProgramInstances();
+int KillMongoProgramInstances();
void goingAwaySoon();
void installShellUtilsLauncher(Scope& scope);