summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2022-05-27 22:40:49 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-03 17:21:59 +0000
commit814159344a60a0e6e53c6fe6aeab3e4317f22396 (patch)
tree90b22a4a9cb3a365cf0b8985f4890a614025d4e7
parent58d6f304e928e620ff4475deb9e8913de9840fe1 (diff)
downloadmongo-814159344a60a0e6e53c6fe6aeab3e4317f22396.tar.gz
SERVER-66843 Use defensive programming in DeadlineFuture destructor
(cherry picked from commit cae77d5066d76ec893a076b2b69fa6f409537a19)
-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);
}