diff options
author | Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> | 2021-10-27 21:18:41 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-27 21:54:30 +0000 |
commit | 4915e76b208b8923004fe2a99f05c663955cdb32 (patch) | |
tree | 8a900c8471143cf23c2265ef252e57d32e67744c | |
parent | 14c24398c1ed8e2c680ed133c48c976d205868f9 (diff) | |
download | mongo-4915e76b208b8923004fe2a99f05c663955cdb32.tar.gz |
SERVER-58194 Have `ThreadContext` present as cleaning up `OpMsgFuzzerFixture`
-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) { |