From 814159344a60a0e6e53c6fe6aeab3e4317f22396 Mon Sep 17 00:00:00 2001 From: Andrew Shuvalov Date: Fri, 27 May 2022 22:40:49 +0000 Subject: SERVER-66843 Use defensive programming in DeadlineFuture destructor (cherry picked from commit cae77d5066d76ec893a076b2b69fa6f409537a19) --- src/mongo/db/process_health/deadline_future.h | 13 +++++++++---- 1 file 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 get() const { @@ -104,6 +108,7 @@ private: std::move(inputFuture).onCompletion([this, self](StatusWith status) { auto lk = stdx::lock_guard(_mutex); _executor->cancel(_timeoutCbHandle.get()); + _timeoutCbHandle = boost::none; if (!get().isReady()) { _outputFuturePromise->setFrom(status); } -- cgit v1.2.1