diff options
author | Matthew Russotto <matthew.russotto@mongodb.com> | 2023-01-27 14:09:30 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-06 18:38:42 +0000 |
commit | 9c65140283c3f72330a94e58bd9ac2c5bd090ced (patch) | |
tree | b420accf8ec8379c802c124d59aa4a966229b1ab | |
parent | 647bfee7a2e21b6589a01dd707a9a540d60c20fe (diff) | |
download | mongo-9c65140283c3f72330a94e58bd9ac2c5bd090ced.tar.gz |
SERVER-73350 SessionKiller should release mutex before creating opctx
-rw-r--r-- | src/mongo/db/session/session_killer.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/db/session/session_killer.cpp b/src/mongo/db/session/session_killer.cpp index f9effaa3f22..fa3c6adda25 100644 --- a/src/mongo/db/session/session_killer.cpp +++ b/src/mongo/db/session/session_killer.cpp @@ -56,15 +56,27 @@ SessionKiller::SessionKiller(ServiceContext* sc, KillFunc killer) // While we're not in shutdown while (!_inShutdown) { // Wait until we're woken up, and should either shutdown, or have something new to reap. - _killerCV.wait(lk, [&] { return _inShutdown || _nextToReap.size(); }); + _killerCV.wait(lk, [&] { return _inShutdown || !_nextToReap.empty(); }); // If we're in shutdown we're done if (_inShutdown) { return; } - // Otherwise make an opctx and head into kill + // Otherwise make an opctx and head into kill. + // + // We must unlock around making an operation context, because making an opCtx can block + // waiting for all old opCtx's to be killed, and elsewhere we hold this mutex while we + // have an opCtx. + lk.unlock(); auto opCtx = cc().makeOperationContext(); + lk.lock(); + + // Double-check shutdown since we released the lock. We don't have to worry about + // _nextToReap becoming empty because only this thread can empty it. + if (_inShutdown) { + return; + } _periodicKill(opCtx.get(), lk); } }); |