summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuoxin Xu <ruoxin.xu@mongodb.com>2020-08-17 12:58:31 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-24 17:01:58 +0000
commit3fb9aa83008866b3610b1d67241d2293d8444e2f (patch)
tree05b8a9a448e68ddb39efb3dcf3e16fe7573921f2
parentbb03863b182807f69bfd4f6874ed1a89c5fea1bf (diff)
downloadmongo-3fb9aa83008866b3610b1d67241d2293d8444e2f.tar.gz
SERVER-50267 Set output limit for rawMongoProgramOutput()
(cherry picked from commit 30acdea3aa54dab658cb76908a8cd9bf35e7762f)
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp10
-rw-r--r--src/mongo/shell/shell_utils_launcher.h1
2 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index 7cef9c37965..d0cc331d10f 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -63,6 +63,7 @@
#include "mongo/base/environment_buffer.h"
#include "mongo/base/error_codes.h"
+#include "mongo/bson/util/builder.h"
#include "mongo/client/dbclient_connection.h"
#include "mongo/db/traffic_reader.h"
#include "mongo/logv2/log.h"
@@ -763,8 +764,15 @@ bool wait_for_pid(ProcessId pid, bool block = true, int* exit_code = nullptr) {
#endif
}
+// Output up to BSONObjMaxUserSize characters of the most recent log output in order to
+// avoid hitting the 16MB size limit of a BSONObject.
BSONObj RawMongoProgramOutput(const BSONObj& args, void* data) {
- return BSON("" << programOutputLogger.str());
+ std::string programLog = programOutputLogger.str();
+ std::size_t sz = programLog.size();
+ const string& outputStr =
+ sz > BSONObjMaxUserSize ? programLog.substr(sz - BSONObjMaxUserSize) : programLog;
+
+ return BSON("" << outputStr);
}
BSONObj ClearRawMongoProgramOutput(const BSONObj& args, void* data) {
diff --git a/src/mongo/shell/shell_utils_launcher.h b/src/mongo/shell/shell_utils_launcher.h
index 10ae1e7d716..9464100aa9b 100644
--- a/src/mongo/shell/shell_utils_launcher.h
+++ b/src/mongo/shell/shell_utils_launcher.h
@@ -66,7 +66,6 @@ void installShellUtilsLauncher(Scope& scope);
class ProgramOutputMultiplexer {
public:
void appendLine(int port, ProcessId pid, const std::string& name, const std::string& line);
- /** @return up to 100000 characters of the most recent log output. */
std::string str() const;
void clear();