diff options
-rw-r--r-- | src/mongo/db/op_msg_fuzzer_fixture.cpp | 29 |
1 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 4918aa2468d..89c81979a49 100644 --- a/src/mongo/db/op_msg_fuzzer_fixture.cpp +++ b/src/mongo/db/op_msg_fuzzer_fixture.cpp @@ -126,17 +126,24 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers) } OpMsgFuzzerFixture::~OpMsgFuzzerFixture() { - CollectionShardingStateFactory::clear(_serviceContext); - - { - auto clientGuard = _clientStrand->bind(); - auto opCtx = _serviceContext->makeOperationContext(clientGuard.get()); - Lock::GlobalLock glk(opCtx.get(), MODE_X); - auto databaseHolder = DatabaseHolder::get(opCtx.get()); - databaseHolder->closeAll(opCtx.get()); - } - - shutdownGlobalStorageEngineCleanly(_serviceContext); + // The following ensures a thread-local instance of `ThreadContext` is available when running + // the destructor code. This is necessary as the main thread uses static storage for the + // instance of `OpMsgFuzzerFixture`, which is not destroyed until after all thread-locals are + // destructed. See SERVER-58194 for more details. + stdx::thread thread([this] { + CollectionShardingStateFactory::clear(_serviceContext); + + { + auto clientGuard = _clientStrand->bind(); + auto opCtx = _serviceContext->makeOperationContext(clientGuard.get()); + Lock::GlobalLock glk(opCtx.get(), MODE_X); + auto databaseHolder = DatabaseHolder::get(opCtx.get()); + databaseHolder->closeAll(opCtx.get()); + } + + shutdownGlobalStorageEngineCleanly(_serviceContext); + }); + thread.join(); } int OpMsgFuzzerFixture::testOneInput(const char* Data, size_t Size) { |