diff options
author | Adam Rayner <adam.rayner@gmail.com> | 2021-12-21 16:37:03 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-21 17:33:20 +0000 |
commit | 3c2effceee65bbf6bcbfcd13a4d2087d15a81aa1 (patch) | |
tree | 7b889c42f0d042344aa3ba4126215aad1a9c409f /src/mongo | |
parent | 7a8a42f465f2ac2cb05904b25fc91dff087c82cf (diff) | |
download | mongo-3c2effceee65bbf6bcbfcd13a4d2087d15a81aa1.tar.gz |
SERVER-61699 Abort startup if audit log rotate fails
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 13 | ||||
-rw-r--r-- | src/mongo/s/mongos_main.cpp | 13 | ||||
-rw-r--r-- | src/mongo/util/exit_code.h | 3 |
3 files changed, 26 insertions, 3 deletions
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index b5780ed1c9f..f70fec727cb 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -1512,7 +1512,18 @@ int mongod_main(int argc, char* argv[]) { } } - audit::rotateAuditLog(); + // Attempt to rotate the audit log pre-emptively on startup to avoid any potential conflicts + // with existing log state. If this rotation fails, then exit nicely with failure + try { + audit::rotateAuditLog(); + } catch (...) { + + Status err = mongo::exceptionToStatus(); + LOGV2(6169900, "Error rotating audit log", "error"_attr = err); + + quickExit(ExitCode::EXIT_AUDIT_ROTATE_ERROR); + } + setUpCollectionShardingState(service); setUpCatalog(service); setUpReplication(service); diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp index 0d14e523838..9fc9eb9b092 100644 --- a/src/mongo/s/mongos_main.cpp +++ b/src/mongo/s/mongos_main.cpp @@ -924,7 +924,18 @@ ExitCode mongos_main(int argc, char* argv[]) { return EXIT_ABRUPT; } - audit::rotateAuditLog(); + // Attempt to rotate the audit log pre-emptively on startup to avoid any potential conflicts + // with existing log state. If this rotation fails, then exit nicely with failure + try { + audit::rotateAuditLog(); + } catch (...) { + + Status err = mongo::exceptionToStatus(); + LOGV2(6169901, "Error rotating audit log", "error"_attr = err); + + quickExit(ExitCode::EXIT_AUDIT_ROTATE_ERROR); + } + registerShutdownTask(cleanupTask); const auto service = getGlobalServiceContext(); diff --git a/src/mongo/util/exit_code.h b/src/mongo/util/exit_code.h index 79024f32f86..d34c7e388ab 100644 --- a/src/mongo/util/exit_code.h +++ b/src/mongo/util/exit_code.h @@ -59,7 +59,8 @@ enum ExitCode : int { EXIT_THREAD_SANITIZER = 66, // Default Exit code for Thread Sanitizer failures EXIT_PROCESS_HEALTH_CHECK = 67, // Process health check triggered the crash. EXIT_UNCAUGHT = 100, // top level exception that wasn't caught - EXIT_TEST = 101 + EXIT_TEST = 101, + EXIT_AUDIT_ROTATE_ERROR = 102 // The startup rotation of audit logs failed }; } // namespace mongo |