summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2022-06-23 19:16:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-23 20:10:18 +0000
commit1b1d8538d0dab776ecccadcecc64f6d7eaebb5e7 (patch)
tree444f1a074eca671513dbd005484093db6ea9c337 /src/mongo/db/s/resharding/resharding_coordinator_service.cpp
parent7ad5fbf86418d2a6f17d553b5888198c5f9de05a (diff)
downloadmongo-1b1d8538d0dab776ecccadcecc64f6d7eaebb5e7.tar.gz
SERVER-67370 Destroy instance metrics object so it's lifetime will not be tied to the future callback function object
Diffstat (limited to 'src/mongo/db/s/resharding/resharding_coordinator_service.cpp')
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
index fe15da0a5ca..9aa5ed7c223 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -1399,6 +1399,14 @@ SemiFuture<void> ReshardingCoordinatorService::ReshardingCoordinator::run(
.onCompletion([outerStatus](Status) { return outerStatus; });
})
.onCompletion([this, self = shared_from_this()](Status status) {
+ _metrics->onStateTransition(toMetricsState(_coordinatorDoc.getState()), boost::none);
+
+ // Destroy metrics early so it's lifetime will not be tied to the lifetime of this
+ // state machine. This is because we have future callbacks copy shared pointers to this
+ // state machine that causes it to live longer than expected and potentially overlap
+ // with a newer instance when stepping up.
+ _metrics.reset();
+
if (!status.isOK()) {
{
auto lg = stdx::lock_guard(_fulfillmentMutex);
@@ -1412,8 +1420,6 @@ SemiFuture<void> ReshardingCoordinatorService::ReshardingCoordinator::run(
}
_reshardingCoordinatorObserver->interrupt(status);
}
-
- _metrics->onStateTransition(toMetricsState(_coordinatorDoc.getState()), boost::none);
})
.semi();
}