summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2022-06-03 15:52:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-03 16:34:57 +0000
commitc3b8c78465ca139c66aa243c2283a88d6d77b46a (patch)
treef354a4ad608290fc7ca6cffb36f1df25a862740d
parenta4ae9e7d4bd762a430f014a881ec5b2f6e2ce087 (diff)
downloadmongo-c3b8c78465ca139c66aa243c2283a88d6d77b46a.tar.gz
SERVER-66843 Use defensive programming in DeadlineFuture destructor
-rw-r--r--src/mongo/db/process_health/deadline_future.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/db/process_health/deadline_future.h b/src/mongo/db/process_health/deadline_future.h
index 5b9e549de0c..83b60c3da89 100644
--- a/src/mongo/db/process_health/deadline_future.h
+++ b/src/mongo/db/process_health/deadline_future.h
@@ -55,10 +55,14 @@ public:
}
~DeadlineFuture() {
- auto lk = stdx::lock_guard(_mutex);
- _executor->cancel(_timeoutCbHandle.get());
- // The _executor holds the shared ptr on this, the callback will set the promise.
- invariant(get().isReady());
+ {
+ auto lk = stdx::lock_guard(_mutex);
+ if (_timeoutCbHandle) {
+ _executor->cancel(_timeoutCbHandle.get());
+ }
+ // The _executor holds the shared ptr on this, the callback will set the promise.
+ invariant(get().isReady());
+ }
}
SharedSemiFuture<ResultStatus> get() const {
@@ -104,6 +108,7 @@ private:
std::move(inputFuture).onCompletion([this, self](StatusWith<ResultStatus> status) {
auto lk = stdx::lock_guard(_mutex);
_executor->cancel(_timeoutCbHandle.get());
+ _timeoutCbHandle = boost::none;
if (!get().isReady()) {
_outputFuturePromise->setFrom(status);
}