Bläddra i källkod

Fix busy waiting up to one second using connection timeout

MHD_daemon_get_timeout computes the time to wait as:
timeout = (last_activity + connection_timeout - MHD_monotonic_sec_counter ()) * 1000

After sleeping timeout milliseconds, MHD_monotonic_sec_counter () will be:

MHD_monotonic_sec_counter () = last_activity + connection_timeout

With that (timeout < (MHD_monotonic_sec_counter () - connection->last_activity)) evaluates to false and the MHD_connection_close_ is not done.
For the next cycle, MHD_daemon_get_timeout() will return 0 and this goes on, until MHD_monotonic_sec_counter jumps to the next second.

This bug causes thousands of unnecessary calls to MHD_run, when a connection timed out.
Alexander Irion 4 år sedan
förälder
incheckning
f5d387df7e
2 ändrade filer med 4 tillägg och 4 borttagningar
  1. 2 2
      src/lib/connection_call_handlers.c
  2. 2 2
      src/microhttpd/connection.c

+ 2 - 2
src/lib/connection_call_handlers.c

@@ -3582,8 +3582,8 @@ MHD_request_handle_idle_ (struct MHD_Request *request)
     time_t 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);

+ 2 - 2
src/microhttpd/connection.c

@@ -4306,8 +4306,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
     time_t 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);