]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5649] CommandMgr timeout is managed as the transaction is progressing.
authorMarcin Siodelski <marcin@isc.org>
Wed, 13 Jun 2018 20:15:44 +0000 (22:15 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 13 Jun 2018 20:15:44 +0000 (22:15 +0200)
src/lib/config/command_mgr.cc

index b9668bc1392dd8da974e1dc2bd1c6edb8dc9c105..8f59001fe25651714a28756ec96fbdbe82309d32 100644 (file)
@@ -75,8 +75,7 @@ public:
         feed_.initModel();
 
         // Start timer for detecting timeouts.
-        timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this),
-                             timeout_ * 1000, IntervalTimer::ONE_SHOT);
+        scheduleTimer();
     }
 
     /// @brief Destructor.
@@ -86,6 +85,12 @@ public:
         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
@@ -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 {
@@ -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);
 
@@ -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();
@@ -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.