diff options
author | Roxane <roxane.fruytier@10gen.com> | 2019-07-01 16:37:29 -0400 |
---|---|---|
committer | Roxane <roxane.fruytier@10gen.com> | 2019-07-09 10:19:51 -0400 |
commit | 9ad917886db091a5b7fde2434eea9095c7145986 (patch) | |
tree | dd3c91822e30c542e7c7878699d769beefa4afce /src | |
parent | a013379db61a39705f9d8e81458026cf613bb064 (diff) | |
download | mongo-9ad917886db091a5b7fde2434eea9095c7145986.tar.gz |
SERVER-33749 Add idleSessionTimeout flag
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 22 | ||||
-rw-r--r-- | src/mongo/shell/shell_options.cpp | 4 | ||||
-rw-r--r-- | src/mongo/shell/shell_options.h | 1 | ||||
-rw-r--r-- | src/mongo/shell/shell_options.idl | 5 |
4 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index 1a5018cf499..a2d3edee8f8 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -177,6 +177,19 @@ enum ShellExitCode : int { Scope* shellMainScope; } +bool isSessionTimedOut() { + static Date_t previousCommandTime = Date_t::now(); + if (shellGlobalParams.idleSessionTimeout > Seconds(0)) { + const Date_t now = Date_t::now(); + + if (now > (previousCommandTime + shellGlobalParams.idleSessionTimeout)) { + return true; + } + previousCommandTime = now; + } + return false; +} + void generateCompletions(const std::string& prefix, std::vector<std::string>& all) { if (prefix.find('"') != std::string::npos) return; @@ -945,6 +958,15 @@ int _main(int argc, char* argv[], char** envp) { free(line); break; } + + // Support idle session lifetime limits + if (isSessionTimedOut()) { + std::cout << "Idle Connection Timeout: Shell session has expired" << std::endl; + if (line) + free(line); + break; + } + if (code == "cls") { free(line); linenoiseClearScreen(); diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp index 325584765db..026cb9af45b 100644 --- a/src/mongo/shell/shell_options.cpp +++ b/src/mongo/shell/shell_options.cpp @@ -237,6 +237,10 @@ Status storeMongoShellOptions(const moe::Environment& params, shellGlobalParams.jsHeapLimitMB = jsHeapLimitMB; } + if (params.count("idleSessionTimeout")) { + shellGlobalParams.idleSessionTimeout = Seconds(params["idleSessionTimeout"].as<int>()); + } + if (shellGlobalParams.url == "*") { StringBuilder sb; sb << "ERROR: " diff --git a/src/mongo/shell/shell_options.h b/src/mongo/shell/shell_options.h index 531c6369790..aad972d0dc1 100644 --- a/src/mongo/shell/shell_options.h +++ b/src/mongo/shell/shell_options.h @@ -80,6 +80,7 @@ struct ShellGlobalParams { int jsHeapLimitMB = 0; bool nokillop = false; + Seconds idleSessionTimeout = Seconds{0}; }; extern ShellGlobalParams shellGlobalParams; diff --git a/src/mongo/shell/shell_options.idl b/src/mongo/shell/shell_options.idl index d4c8ba3694a..dc66354e25e 100644 --- a/src/mongo/shell/shell_options.idl +++ b/src/mongo/shell/shell_options.idl @@ -203,3 +203,8 @@ configs: description: "Remote host name to use for purpose of GSSAPI/Kerberos authentication" arg_vartype: String + "idleSessionTimeout": + description: "Terminate the Shell session if it's been idle for this many seconds" + arg_vartype: Int + default: 0 + validator: {gte: 0} |