From 3720d7e5cd419db95fdbf1b2df0dbd2f6d88ce56 Mon Sep 17 00:00:00 2001 From: Amirsaman Memaripour Date: Tue, 1 Jun 2021 21:55:11 +0000 Subject: SERVER-57347 Fix the data race in OpMsgFuzzerFixture --- src/mongo/db/op_msg_fuzzer_fixture.cpp | 27 ++++++++++++++++----------- src/mongo/db/op_msg_fuzzer_fixture.h | 2 ++ 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(); + _externalState = localExternalState.get(); + + auto localAuthzManager = + std::make_unique(_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(_serviceContext)); @@ -102,17 +118,6 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers) std::make_unique()); Collection::Factory::set(_serviceContext, std::make_unique()); - auto localExternalState = std::make_unique(); - _externalState = localExternalState.get(); - - auto localAuthzManager = - std::make_unique(_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 -- cgit v1.2.1