]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: freq-ctr: Don't compute overshoot value for empty counters
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 14 Dec 2022 09:38:01 +0000 (10:38 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 14 Dec 2022 09:44:17 +0000 (10:44 +0100)
The function computing the excess of events of a frequency counter over the
current period for a target frequency must handle empty counters (no event
and no start date). In this case, no excess must be reported.

Because of this bug, long pauses may be experienced on the bandwith
limitation filter.

This patch must be backported to 2.7.

src/freq_ctr.c

index 602ad9be61d98a163406c61d0e4e35393b8b4f17..9b001e32625bdb548b59ce0519ff625954ef0617 100644 (file)
@@ -147,8 +147,9 @@ ullong freq_ctr_total(const struct freq_ctr *ctr, uint period, int pend)
 }
 
 /* Returns the excess of events (may be negative) over the current period for
- * target frequency <freq>. It returns 0 if the counter is in the future. The
- * result considers the position of the current time within the current period.
+ * target frequency <freq>. It returns 0 if the counter is in the future or if
+ * the counter is empty. The result considers the position of the current time
+ * within the current period.
  *
  * The caller may safely add new events if result is negative or null.
  */
@@ -195,6 +196,11 @@ int freq_ctr_overshoot_period(const struct freq_ctr *ctr, uint period, uint freq
                __ha_cpu_relax();
        };
 
+       if (!curr && !tick) {
+               /* The counter is empty, there is no overshoot */
+               return 0;
+       }
+
        elapsed = HA_ATOMIC_LOAD(&global_now_ms) - tick;
        if (unlikely(elapsed < 0)) {
                /* The counter is in the future, there is no overshoot */