Skip to content

Commit

Permalink
[5649] CommandMgr timeout is managed as the transaction is progressing.
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Jun 13, 2018
1 parent 946c491 commit 57a06fe
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/lib/config/command_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class Connection : public boost::enable_shared_from_this<Connection> {
feed_.initModel();

// Start timer for detecting timeouts.
timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this),
timeout_ * 1000, IntervalTimer::ONE_SHOT);
scheduleTimer();
}

/// @brief Destructor.
Expand All @@ -86,6 +85,12 @@ class Connection : public boost::enable_shared_from_this<Connection> {
timeout_timer_.cancel();
}

/// @brief This method schedules timer or reschedules existing timer.
void scheduleTimer() {
timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this),
timeout_ * 1000, IntervalTimer::ONE_SHOT);
}

/// @brief Close current connection.
///
/// Connection is not closed if the invocation of this method is a result of
Expand Down Expand Up @@ -288,6 +293,9 @@ Connection::receiveHandler(const boost::system::error_code& ec,
LOG_DEBUG(command_logger, DBG_COMMAND, COMMAND_SOCKET_READ)
.arg(bytes_transferred).arg(socket_->getNative());

// Reschedule the timer because the transaction is ongoing.
scheduleTimer();

ConstElementPtr rsp;

try {
Expand All @@ -306,6 +314,10 @@ Connection::receiveHandler(const boost::system::error_code& ec,
ConstElementPtr cmd = feed_.toElement();
response_in_progress_ = true;

// Cancel the timer to make sure that long lasting command
// processing doesn't cause the timeout.
timeout_timer_.cancel();

// If successful, then process it as a command.
rsp = CommandMgr::instance().processCommand(cmd);

Expand All @@ -331,6 +343,10 @@ Connection::receiveHandler(const boost::system::error_code& ec,

} else {

// Reschedule the timer as it may be either canceled or need to be
// updated to not timeout before we manage to the send the reply.
scheduleTimer();

// Let's convert JSON response to text. Note that at this stage
// the rsp pointer is always set.
response_ = rsp->str();
Expand All @@ -354,6 +370,10 @@ Connection::sendHandler(const boost::system::error_code& ec,
}

} else {

// Reschedule the timer because the transaction is ongoing.
scheduleTimer();

// No error. We are in a process of sending a response. Need to
// remove the chunk that we have managed to sent with the previous
// attempt.
Expand Down

0 comments on commit 57a06fe

Please sign in to comment.