]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: listener: Wake proxy's mngmt task up if necessary on session release
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Mar 2024 06:31:56 +0000 (07:31 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Mar 2024 14:20:06 +0000 (15:20 +0100)
When a session is released, listener_release() function is called to notify
the listener. It is an opportunity to resume limited/full listeners. We
first try to resume the listener owning the released session, then all
limited listeners in the global queue and finally all limited listeners in
the frontend's waiting queue. This last step is only performed if there is
no limit applied on the frontend. Nothing is performed if the session rate is
still limited. And it is an issue because if this happens for the last
listener's session, there is no other event to wake the frontend's managment
task up and the listener remains in the limited state.

To fix the issue, when a limit is still applied on the frontent, we must
compute the new wake up date from the sessions rate and schedule the
frontend's managment task.

It is easy to reproduce the issue in SSL by setting a maxconn and a rate
limit on sessions.

This patch should fix the issue #2476. It must be backported to all stable
versions.

src/listener.c

index 37d897a1da342eaf7252e617325bffa83d54be09..86d4c44f5fe0ee03ecceaef7919a383c2f0c23d3 100644 (file)
@@ -1602,6 +1602,22 @@ void listener_release(struct listener *l)
        if (fe && !MT_LIST_ISEMPTY(&fe->listener_queue) &&
            (!fe->fe_sps_lim || freq_ctr_remain(&fe->fe_sess_per_sec, fe->fe_sps_lim, 0) > 0))
                dequeue_proxy_listeners(fe);
+       else {
+               unsigned int wait;
+               int expire = TICK_ETERNITY;
+
+               if (fe->fe_sps_lim &&
+                   (wait = next_event_delay(&fe->fe_sess_per_sec,fe->fe_sps_lim, 0))) {
+                       /* we're blocking because a limit was reached on the number of
+                        * requests/s on the frontend. We want to re-check ASAP, which
+                        * means in 1 ms before estimated expiration date, because the
+                        * timer will have settled down.
+                        */
+                       expire = tick_first(fe->task->expire, tick_add(now_ms, wait));
+                       if (fe->task && tick_isset(expire))
+                               task_schedule(fe->task, expire);
+               }
+       }
 }
 
 /* Initializes the listener queues. Returns 0 on success, otherwise ERR_* flags */