Skip to content

Commit

Permalink
[5649] Manage HTTP connection timeout for progressing transaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Jun 13, 2018
1 parent 57a06fe commit 24e93ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/lib/http/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ HttpConnection:: HttpConnection(asiolink::IOService& io_service,
const long request_timeout,
const long idle_timeout)
: request_timer_(io_service),
request_timer_setup_(false),
request_timeout_(request_timeout),
idle_timeout_(idle_timeout),
socket_(io_service),
Expand All @@ -65,7 +64,6 @@ HttpConnection::~HttpConnection() {

void
HttpConnection::close() {
request_timer_setup_ = false;
request_timer_.cancel();
socket_.close();
}
Expand Down Expand Up @@ -199,6 +197,9 @@ HttpConnection::socketReadCallback(boost::system::error_code ec, size_t length)
}
}

// Receiving is in progress, so push back the timeout.
setupRequestTimer();

if (length != 0) {
LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_DETAIL_DATA,
HTTP_DATA_RECEIVED)
Expand Down Expand Up @@ -271,11 +272,18 @@ HttpConnection::socketWriteCallback(boost::system::error_code ec, size_t length)
// We got EWOULDBLOCK or EAGAIN which indicate that we may be able to
// read something from the socket on the next attempt.
} else {
// Sending is in progress, so push back the timeout.
setupRequestTimer();

doWrite();
}
}


if (length <= output_buf_.size()) {
// Sending is in progress, so push back the timeout.
setupRequestTimer();

output_buf_.erase(0, length);
doWrite();

Expand Down Expand Up @@ -306,17 +314,13 @@ HttpConnection::setupRequestTimer() {
// because IntervalTimer already passes shared pointer to the
// IntervalTimerImpl to make sure that the callback remains
// valid.
if (!request_timer_setup_) {
request_timer_setup_ = true;
request_timer_.setup(boost::bind(&HttpConnection::requestTimeoutCallback,
this),
request_timeout_, IntervalTimer::ONE_SHOT);
}
request_timer_.setup(boost::bind(&HttpConnection::requestTimeoutCallback,
this),
request_timeout_, IntervalTimer::ONE_SHOT);
}

void
HttpConnection::setupIdleTimer() {
request_timer_setup_ = false;
request_timer_.setup(boost::bind(&HttpConnection::idleTimeoutCallback,
this),
idle_timeout_, IntervalTimer::ONE_SHOT);
Expand Down
2 changes: 0 additions & 2 deletions src/lib/http/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ class HttpConnection : public boost::enable_shared_from_this<HttpConnection> {
/// @brief Timer used to detect Request Timeout.
asiolink::IntervalTimer request_timer_;

bool request_timer_setup_;

/// @brief Configured Request Timeout in milliseconds.
long request_timeout_;

Expand Down

0 comments on commit 24e93ec

Please sign in to comment.