diff options
author | Ruoxin Xu <ruoxin.xu@mongodb.com> | 2020-08-17 12:58:31 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-07 16:11:19 +0000 |
commit | 8794a7151d23e787fdc7a4410dffc9a89a0cfa74 (patch) | |
tree | 7f0ad44c1079962000332942a486ca4c700fac4c | |
parent | d8319b3775e9b6952c32a9c0599fce8ebb0d18c5 (diff) | |
download | mongo-8794a7151d23e787fdc7a4410dffc9a89a0cfa74.tar.gz |
SERVER-50267 Set output limit for rawMongoProgramOutput()
(cherry picked from commit 30acdea3aa54dab658cb76908a8cd9bf35e7762f)
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.cpp | 9 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.h | 1 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp index 80c3b270b5e..3946fa9aceb 100644 --- a/src/mongo/shell/shell_utils_launcher.cpp +++ b/src/mongo/shell/shell_utils_launcher.cpp @@ -744,8 +744,15 @@ bool wait_for_pid(ProcessId pid, bool block = true, int* exit_code = NULL) { #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 0ab14b7227c..321e35f24e9 100644 --- a/src/mongo/shell/shell_utils_launcher.h +++ b/src/mongo/shell/shell_utils_launcher.h @@ -68,7 +68,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(); |