diff options
author | Andrew Shuvalov <andrew.shuvalov@mongodb.com> | 2022-06-03 16:00:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-03 16:34:58 +0000 |
commit | c01852d88959b1bae0582c780af764711da765ef (patch) | |
tree | 51d3cdba45d50c7a3a9bc68386d1854b78b7722b | |
parent | 5524aa559106649f147a31315938e916b47b69c9 (diff) | |
download | mongo-c01852d88959b1bae0582c780af764711da765ef.tar.gz |
SERVER-66843 Use defensive programming in DeadlineFuture destructor
-rw-r--r-- | src/mongo/db/process_health/deadline_future.h | 13 |
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); } |