summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmirsaman Memaripour <amirsaman.memaripour@mongodb.com>2021-06-01 21:55:11 +0000
committerAmirsaman Memaripour <amirsaman.memaripour@mongodb.com>2021-06-28 19:31:55 +0000
commit903728cba6ef183f1ecf205b5ae9668aee42e630 (patch)
tree2e715c34c3781b357667f40222f4923c3c3a8145
parentb6a243b478a6448f4b3f73cf064fd146a4a69d33 (diff)
downloadmongo-903728cba6ef183f1ecf205b5ae9668aee42e630.tar.gz
SERVER-57347 Fix the data race in OpMsgFuzzerFixturer5.0.0-rc5
(cherry picked from commit 3720d7e5cd419db95fdbf1b2df0dbd2f6d88ce56)
-rw-r--r--src/mongo/db/op_msg_fuzzer_fixture.cpp27
-rw-r--r--src/mongo/db/op_msg_fuzzer_fixture.h2
2 files changed, 18 insertions, 11 deletions
diff --git a/src/mongo/db/op_msg_fuzzer_fixture.cpp b/src/mongo/db/op_msg_fuzzer_fixture.cpp
index 5efdddd3223..a2f6d29eadc 100644
--- a/src/mongo/db/op_msg_fuzzer_fixture.cpp
+++ b/src/mongo/db/op_msg_fuzzer_fixture.cpp
@@ -59,6 +59,21 @@ namespace {
constexpr auto kTempDirStem = "op_msg_fuzzer_fixture"_sd;
}
+// This must be called before creating any new threads that may access `AuthorizationManager` to
+// avoid a data-race.
+void OpMsgFuzzerFixture::_setAuthorizationManager() {
+ auto localExternalState = std::make_unique<AuthzManagerExternalStateMock>();
+ _externalState = localExternalState.get();
+
+ auto localAuthzManager =
+ std::make_unique<AuthorizationManagerImpl>(_serviceContext, std::move(localExternalState));
+ _authzManager = localAuthzManager.get();
+ _externalState->setAuthorizationManager(_authzManager);
+ _authzManager->setAuthEnabled(true);
+
+ AuthorizationManager::set(_serviceContext, std::move(localAuthzManager));
+}
+
OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
: _dir(kTempDirStem.toString()) {
if (!skipGlobalInitializers) {
@@ -70,6 +85,7 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
_session = _transportLayer.createSession();
_serviceContext = getGlobalServiceContext();
+ _setAuthorizationManager();
_serviceContext->setServiceEntryPoint(
std::make_unique<ServiceEntryPointMongod>(_serviceContext));
@@ -102,17 +118,6 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
std::make_unique<IndexAccessMethodFactoryImpl>());
Collection::Factory::set(_serviceContext, std::make_unique<CollectionImpl::FactoryImpl>());
- auto localExternalState = std::make_unique<AuthzManagerExternalStateMock>();
- _externalState = localExternalState.get();
-
- auto localAuthzManager =
- std::make_unique<AuthorizationManagerImpl>(_serviceContext, std::move(localExternalState));
- _authzManager = localAuthzManager.get();
- _externalState->setAuthorizationManager(_authzManager);
- _authzManager->setAuthEnabled(true);
-
- AuthorizationManager::set(_serviceContext, std::move(localAuthzManager));
-
// Setup the repl coordinator in standalone mode so we don't need an oplog etc.
repl::ReplicationCoordinator::set(
_serviceContext,
diff --git a/src/mongo/db/op_msg_fuzzer_fixture.h b/src/mongo/db/op_msg_fuzzer_fixture.h
index b519fa98271..4eb95dbf16d 100644
--- a/src/mongo/db/op_msg_fuzzer_fixture.h
+++ b/src/mongo/db/op_msg_fuzzer_fixture.h
@@ -55,6 +55,8 @@ public:
int testOneInput(const char* Data, size_t Size);
private:
+ void _setAuthorizationManager();
+
const LogicalTime kInMemoryLogicalTime = LogicalTime(Timestamp(3, 1));
// This member is responsible for both creating and deleting the base directory. Think of it as