diff options
author | Eric Milkie <milkie@10gen.com> | 2016-09-15 13:00:00 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2016-09-29 08:47:13 -0400 |
commit | 0b879b315473bb2d0a296a782a1dc8cf7fac8e20 (patch) | |
tree | b157ee2a40f5a39fd25af7e10e138ea223214a47 /src/mongo | |
parent | 7f6eb7f2361addf3f75308bf1603caa8cdc71b68 (diff) | |
download | mongo-0b879b315473bb2d0a296a782a1dc8cf7fac8e20.tar.gz |
SERVER-25777 When stopping a spawned process, MongoDB shell will now abort after implicitly falling back to SIGKILL after timeout.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 3 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.cpp | 39 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.h | 2 |
3 files changed, 19 insertions, 25 deletions
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index 7b91a93dddd..089e158144b 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -755,6 +755,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 d6904833a5e..dbd9ca4a1ef 100644 --- a/src/mongo/shell/shell_utils_launcher.cpp +++ b/src/mongo/shell/shell_utils_launcher.cpp @@ -885,7 +885,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; @@ -898,32 +897,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 < 6000; ++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; } @@ -979,12 +964,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 3167b9a28b3..f5d68bb6bc2 100644 --- a/src/mongo/shell/shell_utils_launcher.h +++ b/src/mongo/shell/shell_utils_launcher.h @@ -53,7 +53,7 @@ struct MongoProgramScope { MongoProgramScope() {} // Avoid 'unused variable' warning. ~MongoProgramScope(); }; -void KillMongoProgramInstances(); +int KillMongoProgramInstances(); void installShellUtilsLauncher(Scope& scope); |