Commit 299a38f8 authored by rdhabalia's avatar rdhabalia Committed by Facebook Github Bot

Allow HHWheelTimer to set default-timeout

Summary:
We are using facebook::proxygen to build Http-utility on top of it. One of the main server-connector class `Proxygen::HTTPConnector` requires `folly::HHWheelTimer` to perform timer stuff inside it.

Now, `folly::HHWheelTimer` is a very large object and we would like to avoid `folly::HHWheelTimer` creation for every new `Proxygen::HTTPConnector` therefore, we are thinking to reuse `EventBase::timer()` that creates one timer per EventBase (application creates it 1 per io thread).

But `EventBase::timer()` creates timer with default-time and caller can not modify it. Because of that other dependent component can't use it and proxygen gives below error:
```
F0522 23:50:19.629158  7775 WheelTimerInstance.cpp:71] Check failed: defaultTimeoutMS_.count() >= 0 (-1 vs. 0)
*** Check failure stack trace: ***
    @     0x7f5e6ce26e6d  (unknown)
    @     0x7f5e6ce28ced  (unknown)
    @     0x7f5e6ce26a5c  (unknown)
    @     0x7f5e6ce2963e  (unknown)
    @     0x7f5e6de8c1ad  proxygen::WheelTimerInstance::scheduleTimeout()
    @     0x7f5e6de7c059  proxygen::HTTPTransaction::HTTPTransaction()
    @     0x7f5e6deacff1  ...
    @     0x7f5e6deaa23a  proxygen::HTTPSession::createTransaction()
    @           0x4f7f93  proxygen::HTTPUpstreamSession::newTransaction()
    @           0x4ad9a4  Sherpa::HttpSession::sendRequest()
    @           0x4aee08  Sherpa::HttpSession::connectSuccess()
    @           0x4f5c69  proxygen::HTTPConnector::connectSuccess()
    @     0x7f5e6d47e414  folly::AsyncSocket::handleConnect()
    @     0x7f5e6d48769d  folly::AsyncSocket::handleWrite()
    @     0x7f5e6d47a05c  folly::AsyncSocket::ioReady()
```

- add `setDefaultTimeout()` method into timer so, application can configure it.

- No functional change but it facilitates application to configure defaultTimeout after `folly::HHWheelTimer` is created.
Closes https://github.com/facebook/folly/pull/850

Reviewed By: djwatson

Differential Revision: D8123617

Pulled By: yfeldblum

fbshipit-source-id: 4dd9b19506bea380239200b6207ac05a40a0686c
parent 4835f0e5
......@@ -195,6 +195,13 @@ class HHWheelTimer : private folly::AsyncTimeout,
return defaultTimeout_;
}
/**
* Set the default timeout interval for this HHWheelTimer.
*/
void setDefaultTimeout(std::chrono::milliseconds timeout) {
defaultTimeout_ = timeout;
}
/**
* Schedule the specified Callback to be invoked after the
* specified timeout interval.
......
......@@ -124,6 +124,17 @@ TEST_F(HHWheelTimerTest, TestSchedulingWithinCallback) {
ASSERT_EQ(t2.timestamps.size(), 1);
}
/*
* Test changing default-timeout in timer.
*/
TEST_F(HHWheelTimerTest, TestSetDefaultTimeout) {
HHWheelTimer& t = eventBase.timer();
t.setDefaultTimeout(milliseconds(1000));
// verify: default-time has been modified
ASSERT_EQ(t.getDefaultTimeout(), milliseconds(1000));
}
/*
* Test cancelling a timeout when it is scheduled to be fired right away.
*/
......
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