diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2018-09-19 10:31:11 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2018-10-05 18:36:39 -0400 |
commit | 90535dd9fc4355969a2adc3ff921537a464845fb (patch) | |
tree | 818471f310ce5fb486f795f0986fb6c504a212ec | |
parent | 7c26f67b8fd09740b5b55b4f031e3f95fab25fd0 (diff) | |
download | mongo-90535dd9fc4355969a2adc3ff921537a464845fb.tar.gz |
SERVER-36978 TaskRunner must ensure Client is initialized for thread before running tasks
(cherry picked from commit fb4e163ff4a8ce5057b66b24f41f1bf193e2058c)
-rw-r--r-- | src/mongo/db/repl/task_runner.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/mongo/db/repl/task_runner.cpp b/src/mongo/db/repl/task_runner.cpp index 210718bba3e..134160bbdf1 100644 --- a/src/mongo/db/repl/task_runner.cpp +++ b/src/mongo/db/repl/task_runner.cpp @@ -131,20 +131,17 @@ void TaskRunner::join() { } void TaskRunner::_runTasks() { - Client* client = nullptr; + // We initialize cc() because ServiceContextMongoD::_newOpCtx() expects cc() to be equal to the + // client used to create the operation context. + Client::initThreadIfNotAlready(); + Client* client = &cc(); + if (AuthorizationManager::get(client->getServiceContext())->isAuthEnabled()) { + AuthorizationSession::get(client)->grantInternalAuthorization(); + } ServiceContext::UniqueOperationContext txn; while (Task task = _waitForNextTask()) { if (!txn) { - if (!client) { - // We initialize cc() because ServiceContextMongoD::_newOpCtx() expects cc() - // to be equal to the client used to create the operation context. - Client::initThreadIfNotAlready(); - client = &cc(); - if (getGlobalAuthorizationManager()->isAuthEnabled()) { - AuthorizationSession::get(client)->grantInternalAuthorization(); - } - } txn = client->makeOperationContext(); } |