Commit e7c9b18f authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Be more explicit about exceptions in ThreadWheelTimekeeper

Summary: [Folly] Be more explicit about exceptions in `ThreadWheelTimekeeper`.

Differential Revision: D6842211

fbshipit-source-id: 9ef9c7149b610bbad76a08ef771aa13870d4467f
parent cd964941
...@@ -40,7 +40,7 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>, ...@@ -40,7 +40,7 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>,
// hold a ref count to it. The ref count will be released when Core goes // hold a ref count to it. The ref count will be released when Core goes
// away which happens when both Promise and Future go away // away which happens when both Promise and Future go away
cob->promise_.setInterruptHandler( cob->promise_.setInterruptHandler(
[cob](const folly::exception_wrapper&) { cob->interruptHandler(); }); [cob](exception_wrapper ew) { cob->interruptHandler(std::move(ew)); });
return cob; return cob;
} }
...@@ -67,17 +67,19 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>, ...@@ -67,17 +67,19 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>,
} }
} }
void interruptHandler() { void interruptHandler(exception_wrapper ew) {
// Capture shared_ptr of self in lambda, if we don't do this, object // Capture shared_ptr of self in lambda, if we don't do this, object
// may go away before the lambda is executed from event base thread. // may go away before the lambda is executed from event base thread.
// This is not racing with timeoutExpired anymore because this is called // This is not racing with timeoutExpired anymore because this is called
// through Future, which means Core is still alive and keeping a ref count // through Future, which means Core is still alive and keeping a ref count
// on us, so what timeouExpired is doing won't make the object go away // on us, so what timeouExpired is doing won't make the object go away
base_->runInEventBaseThread([me = shared_from_this()] { base_->runInEventBaseThread([me = shared_from_this(), ew = std::move(ew)] {
me->cancelTimeout(); me->cancelTimeout();
// Don't need Promise anymore, break the circular reference // Don't need Promise anymore, break the circular reference
auto promise = me->stealPromise(); auto promise = me->stealPromise();
(void)promise; if (!promise.isFulfilled()) {
promise.setException(std::move(ew));
}
}); });
} }
}; };
...@@ -131,7 +133,9 @@ Future<Unit> ThreadWheelTimekeeper::after(Duration dur) { ...@@ -131,7 +133,9 @@ Future<Unit> ThreadWheelTimekeeper::after(Duration dur) {
// They are somewhat racy but given the rare chance this could fail, // They are somewhat racy but given the rare chance this could fail,
// I don't see it is introducing any problem yet. // I don't see it is introducing any problem yet.
auto promise = cob->stealPromise(); auto promise = cob->stealPromise();
(void)promise; if (!promise.isFulfilled()) {
promise.setException(NoTimekeeper{});
}
} }
return f; return f;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment