Skip to content

Commit

Permalink
SERVER-57347 Fix the data race in OpMsgFuzzerFixture
Browse files Browse the repository at this point in the history
(cherry picked from commit 3720d7e)
  • Loading branch information
samanca committed Jun 28, 2021
1 parent b6a243b commit 903728c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/mongo/db/op_msg_fuzzer_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -70,6 +85,7 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
_session = _transportLayer.createSession();

_serviceContext = getGlobalServiceContext();
_setAuthorizationManager();
_serviceContext->setServiceEntryPoint(
std::make_unique<ServiceEntryPointMongod>(_serviceContext));

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/db/op_msg_fuzzer_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class OpMsgFuzzerFixture {
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
Expand Down

0 comments on commit 903728c

Please sign in to comment.