diff options
Diffstat (limited to 'src/mongo/db/op_msg_fuzzer_fixture.cpp')
-rw-r--r-- | src/mongo/db/op_msg_fuzzer_fixture.cpp | 27 |
1 files changed, 16 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, |