diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2018-06-11 10:37:40 -0400 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2018-06-11 17:41:40 -0400 |
commit | 43c2f1b3564c4ea6a342525052a814c9fa98b946 (patch) | |
tree | 5719adc44b23937d1ebaab3e45eabe1b107a739a | |
parent | a79b03763ec3bdcdd4858a5eeae4718984158df1 (diff) | |
download | mongo-43c2f1b3564c4ea6a342525052a814c9fa98b946.tar.gz |
SERVER-35527 Ignore session information on the embedded version of mongod
(cherry picked from commit 7070ff68a75f10a906c0b0cdbbf50697ec1372c2)
-rw-r--r-- | src/mongo/db/initialize_operation_session_info.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/logical_session_id_test.cpp | 16 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/mongo/db/initialize_operation_session_info.cpp b/src/mongo/db/initialize_operation_session_info.cpp index a4f3d005b10..d94cfdb78bc 100644 --- a/src/mongo/db/initialize_operation_session_info.cpp +++ b/src/mongo/db/initialize_operation_session_info.cpp @@ -64,9 +64,14 @@ boost::optional<OperationSessionInfoFromClient> initializeOperationSessionInfo( if (osi.getSessionId()) { stdx::lock_guard<Client> lk(*opCtx->getClient()); - opCtx->setLogicalSessionId(makeLogicalSessionId(osi.getSessionId().get(), opCtx)); + auto lsc = LogicalSessionCache::get(opCtx->getServiceContext()); + if (!lsc) { + // Ignore session information if the logical session cache has not been set up, e.g. on + // the embedded version of mongod. + return boost::none; + } - LogicalSessionCache* lsc = LogicalSessionCache::get(opCtx->getServiceContext()); + opCtx->setLogicalSessionId(makeLogicalSessionId(osi.getSessionId().get(), opCtx)); lsc->vivify(opCtx, opCtx->getLogicalSessionId().get()); } else { uassert(ErrorCodes::InvalidOptions, diff --git a/src/mongo/db/logical_session_id_test.cpp b/src/mongo/db/logical_session_id_test.cpp index 3d1d1e0563e..bc5befe3a96 100644 --- a/src/mongo/db/logical_session_id_test.cpp +++ b/src/mongo/db/logical_session_id_test.cpp @@ -339,6 +339,22 @@ TEST_F(LogicalSessionIdTest, InitializeOperationSessionInfo_SupportsDocLockingFa ErrorCodes::IllegalOperation); } +TEST_F(LogicalSessionIdTest, InitializeOperationSessionInfo_IgnoresInfoIfNoCache) { + addSimpleUser(UserName("simple", "test")); + LogicalSessionFromClient lsid; + lsid.setId(UUID::gen()); + + LogicalSessionCache::set(_opCtx->getServiceContext(), nullptr); + + ASSERT_FALSE(initializeOperationSessionInfo( + _opCtx.get(), + BSON("TestCmd" << 1 << "lsid" << lsid.toBSON() << "txnNumber" << 100LL << "OtherField" + << "TestField"), + true, + true, + true)); +} + TEST_F(LogicalSessionIdTest, ConstructorFromClientWithTooLongName) { auto id = UUID::gen(); |