summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2017-03-21 21:05:45 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2017-03-22 16:03:09 -0400
commit7361e94af31142ec018ccad70b0398e3a472eba5 (patch)
treecd48ec129c02132a9902026f76f415989cb7cfbe /src
parent5d141bce7219aeb34d3de8cfae68d643bf9a3a16 (diff)
downloadmongo-7361e94af31142ec018ccad70b0398e3a472eba5.tar.gz
SERVER-28181 Fix the deadlock in OplogFetcher's constructor.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/bgsync.cpp14
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());