libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] [PATCH] imprecision calculations of timeouts


From: Vitaliy T
Subject: [libmicrohttpd] [PATCH] imprecision calculations of timeouts
Date: Thu, 16 Mar 2017 22:27:42 +0300

Because of timeouts have time_t type, it is possible that deltas will
be rounded to a greater value (augment by 1, specifically).

An example:
1. connection timeout is set to 1.
2. real delta between MHD_monotonic_sec_counter() -
connection->last_activity is 0.7.
3. delta before patch is 1 and comparison via '<=' leads to disconnect.

This is actual for very small timeouts values, where even microseconds
are important.


diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index c3c7be8b..833a0d87 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3215,7 +3215,7 @@ MHD_connection_handle_idle (struct
MHD_Connection *connection)
       unsigned int timeout;
       timeout = connection->connection_timeout;
       if ( (0 != timeout) &&
-           (timeout <= (MHD_monotonic_sec_counter() -
connection->last_activity)) )
+           (timeout < (MHD_monotonic_sec_counter() -
connection->last_activity)) )
         {
           MHD_connection_close_ (connection,
                                  MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
diff --git a/src/microhttpd/connection_https.c
b/src/microhttpd/connection_https.c
index 5a05bf3b..f023c2f1 100644
--- a/src/microhttpd/connection_https.c
+++ b/src/microhttpd/connection_https.c
@@ -144,7 +144,7 @@ MHD_tls_connection_handle_idle (struct
MHD_Connection *connection)
     return MHD_connection_handle_idle (connection);
   timeout = connection->connection_timeout;
   if ( (timeout != 0) &&
-       (timeout <= (MHD_monotonic_sec_counter() - connection->last_activity)))
+       (timeout < (MHD_monotonic_sec_counter() - connection->last_activity)))
     MHD_connection_close_ (connection,
                            MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
   switch (connection->state)


-- 
With Best Regards,
Vitaliy V. Tokarev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]