From 57d7938c49da06122d4d43054ff89e1881d0209f Mon Sep 17 00:00:00 2001 From: Misha Tyulenev Date: Tue, 3 Jul 2018 11:50:52 -0400 Subject: SERVER-34810 do not kill new sessions in logical session cache --- src/mongo/db/logical_session_cache_impl.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mongo/db/logical_session_cache_impl.cpp b/src/mongo/db/logical_session_cache_impl.cpp index 3c1082dbc35..8b46cbb4638 100644 --- a/src/mongo/db/logical_session_cache_impl.cpp +++ b/src/mongo/db/logical_session_cache_impl.cpp @@ -346,13 +346,24 @@ void LogicalSessionCacheImpl::_refresh(Client* client) { _stats.setLastSessionsCollectionJobEntriesEnded(explicitlyEndingSessions.size()); } - // Find which running, but not recently active sessions, are expired, and add them // to the list of sessions to kill cursors for KillAllSessionsByPatternSet patterns; auto openCursorSessions = _service->getOpenCursorSessions(); + // Exclude sessions added to _activeSessions from the openCursorSession to avoid race between + // killing cursors on the removed sessions and creating sessions. + { + stdx::lock_guard lk(_cacheMutex); + + for (const auto& it : _activeSessions) { + auto newSessionIt = openCursorSessions.find(it.first); + if (newSessionIt != openCursorSessions.end()) { + openCursorSessions.erase(newSessionIt); + } + } + } // think about pruning ending and active out of openCursorSessions auto statusAndRemovedSessions = _sessionsColl->findRemovedSessions(opCtx, openCursorSessions); -- cgit v1.2.1