summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
authorGabriel Marks <gabriel.marks@mongodb.com>2022-05-27 16:39:11 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-17 15:12:54 +0000
commit9783ab2652858dd6e9175160d6d7a4c14e2d5ea5 (patch)
treeca144c7e9f49d54aae8b19da5ed02d00cea8945f /src/mongo/util
parent6192908ab3bcf8350e9ec5c7ecc6654d5708c320 (diff)
downloadmongo-9783ab2652858dd6e9175160d6d7a4c14e2d5ea5.tar.gz
SERVER-63843 Don't allow recursive doLog in sync signal handlers
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/signal_handlers_synchronous.cpp56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/mongo/util/signal_handlers_synchronous.cpp b/src/mongo/util/signal_handlers_synchronous.cpp
index 8f052ea134b..59e2e2ef923 100644
--- a/src/mongo/util/signal_handlers_synchronous.cpp
+++ b/src/mongo/util/signal_handlers_synchronous.cpp
@@ -65,6 +65,8 @@ namespace mongo {
namespace {
+using namespace fmt::literals;
+
#if defined(_WIN32)
const char* strsignal(int signalNum) {
// should only see SIGABRT on windows
@@ -191,22 +193,38 @@ private:
stdx::mutex MallocFreeOStreamGuard::_streamMutex; // NOLINT
thread_local int MallocFreeOStreamGuard::terminateDepth = 0;
+void logNoRecursion(StringData message) {
+ // If we were within a log call when we hit a signal, don't call back into the logging
+ // subsystem.
+ if (logv2::loggingInProgress()) {
+ logv2::signalSafeWriteToStderr(message);
+ } else {
+ LOGV2_FATAL_CONTINUE(6384300, "Writing fatal message", "message"_attr = message);
+ }
+}
+
// must hold MallocFreeOStreamGuard to call
void writeMallocFreeStreamToLog() {
- LOGV2_FATAL_OPTIONS(
- 4757800,
- logv2::LogOptions(logv2::FatalMode::kContinue, logv2::LogTruncation::Disabled),
- "{message}",
- "Writing fatal message",
- "message"_attr = mallocFreeOStream.str());
+ mallocFreeOStream << "\n";
+ logNoRecursion(mallocFreeOStream.str());
mallocFreeOStream.rewind();
}
// must hold MallocFreeOStreamGuard to call
+void printStackTraceNoRecursion() {
+ if (logv2::loggingInProgress()) {
+ printStackTrace(mallocFreeOStream);
+ writeMallocFreeStreamToLog();
+ } else {
+ printStackTrace();
+ }
+}
+
+// must hold MallocFreeOStreamGuard to call
void printSignalAndBacktrace(int signalNum) {
- mallocFreeOStream << "Got signal: " << signalNum << " (" << strsignal(signalNum) << ").\n";
+ mallocFreeOStream << "Got signal: " << signalNum << " (" << strsignal(signalNum) << ").";
writeMallocFreeStreamToLog();
- printStackTrace();
+ printStackTraceNoRecursion();
}
// this will be called in certain c++ error cases, for example if there are two active
@@ -222,7 +240,7 @@ void myTerminate() {
mallocFreeOStream << " No exception is active";
}
writeMallocFreeStreamToLog();
- printStackTrace();
+ printStackTraceNoRecursion();
breakpoint();
endProcessWithSignal(SIGABRT);
}
@@ -241,22 +259,16 @@ void myInvalidParameterHandler(const wchar_t* expression,
const wchar_t* file,
unsigned int line,
uintptr_t pReserved) {
- LOGV2_FATAL_CONTINUE(
- 23815,
- "Invalid parameter detected in function {function} in {file} at line {line} "
- "with expression '{expression}'",
- "Invalid parameter detected",
- "function"_attr = toUtf8String(function),
- "file"_attr = toUtf8String(file),
- "line"_attr = line,
- "expression"_attr = toUtf8String(expression));
+
+ logNoRecursion(
+ "Invalid parameter detected in function {} in {} at line {} with expression '{}'\n"_format(
+ toUtf8String(function), toUtf8String(file), line, toUtf8String(expression)));
abruptQuit(SIGABRT);
}
void myPureCallHandler() {
- LOGV2_FATAL_CONTINUE(23818,
- "Pure call handler invoked. Immediate exit due to invalid pure call");
+ logNoRecursion("Pure call handler invoked. Immediate exit due to invalid pure call\n");
abruptQuit(SIGABRT);
}
@@ -345,9 +357,9 @@ void setupSynchronousSignalHandlers() {
void reportOutOfMemoryErrorAndExit() {
MallocFreeOStreamGuard lk{};
- mallocFreeOStream << "out of memory.\n";
+ mallocFreeOStream << "out of memory.";
writeMallocFreeStreamToLog();
- printStackTrace();
+ printStackTraceNoRecursion();
quickExit(EXIT_ABRUPT);
}