diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2017-03-21 21:05:45 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2017-03-22 16:03:09 -0400 |
commit | 7361e94af31142ec018ccad70b0398e3a472eba5 (patch) | |
tree | cd48ec129c02132a9902026f76f415989cb7cfbe /src | |
parent | 5d141bce7219aeb34d3de8cfae68d643bf9a3a16 (diff) | |
download | mongo-7361e94af31142ec018ccad70b0398e3a472eba5.tar.gz |
SERVER-28181 Fix the deadlock in OplogFetcher's constructor.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/bgsync.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index 86cc962c926..79d7d294f63 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -380,20 +380,18 @@ void BackgroundSync::_produce(OperationContext* opCtx) { _replCoord, _replicationCoordinatorExternalState, this); OplogFetcher* oplogFetcher; try { - auto executor = _replicationCoordinatorExternalState->getTaskExecutor(); - auto config = _replCoord->getConfig(); auto onOplogFetcherShutdownCallbackFn = [&fetcherReturnStatus](const Status& status, const OpTimeWithHash& lastFetched) { fetcherReturnStatus = status; }; - - stdx::lock_guard<stdx::mutex> lock(_mutex); - _oplogFetcher = stdx::make_unique<OplogFetcher>( - executor, + // The construction of OplogFetcher has to be outside bgsync mutex, because it calls + // replication coordinator. + auto oplogFetcherPtr = stdx::make_unique<OplogFetcher>( + _replicationCoordinatorExternalState->getTaskExecutor(), OpTimeWithHash(lastHashFetched, lastOpTimeFetched), source, NamespaceString(rsOplogName), - config, + _replCoord->getConfig(), _replicationCoordinatorExternalState->getOplogFetcherMaxFetcherRestarts(), syncSourceResp.rbid, true /* requireFresherSyncSource */, @@ -404,6 +402,8 @@ void BackgroundSync::_produce(OperationContext* opCtx) { stdx::placeholders::_2, stdx::placeholders::_3), onOplogFetcherShutdownCallbackFn); + stdx::lock_guard<stdx::mutex> lock(_mutex); + _oplogFetcher = std::move(oplogFetcherPtr); oplogFetcher = _oplogFetcher.get(); } catch (const mongo::DBException& ex) { fassertFailedWithStatus(34440, exceptionToStatus()); |