]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: checks: restore legacy on-error fastinter behavior
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 7 Dec 2022 11:17:24 +0000 (12:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Dec 2022 16:03:55 +0000 (17:03 +0100)
With previous commit, 9e080bf ("BUG/MINOR: checks: make sure fastinter is used
even on forced transitions"), on-error mark-down|sudden-death|fail-check are
now working as expected.

However, on-error fastinter remains broken because srv_getinter(), used in
the above commit to check the expiration date, won't return fastinter interval
if server health is maxed out (which is the case with on-error fastinter mode).

To fix this, we introduce a check flag named CHK_ST_FASTINTER.
This flag is set when on-error is triggered. This way we can force
srv_getinter() to return fastinter interval whenever the flag is set.
The flag is automatically cleared as soon as the new check task expiry is
recalculated in process_chk_conn().
This restores original behavior prior to d114f4a ("MEDIUM: checks: spread the
checks load over random threads").

It must be backported to 2.7 along with the aforementioned commits.

include/haproxy/check-t.h
src/check.c
src/server.c

index 6c569c39d563eea122b6fb34d453fb283ca86fd4..c489ae3513c64a8b03e17680ec427d3ee12f47bf 100644 (file)
@@ -57,6 +57,7 @@ enum chk_result {
 #define CHK_ST_CLOSE_CONN       0x0100  /* check is waiting that the connection gets closed */
 #define CHK_ST_PURGE            0x0200  /* check must be freed */
 #define CHK_ST_SLEEPING         0x0400  /* check was sleeping */
+#define CHK_ST_FASTINTER        0x0800  /* force fastinter check */
 
 /* check status */
 enum healthcheck_status {
index 0f5202898a83fb6f5a357402d4a19e8c8b93c58d..931829fb524897837c1dcefbbd95b21aa09dd02f 100644 (file)
@@ -670,6 +670,11 @@ void __health_adjust(struct server *s, short status)
 
        HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
 
+       /* force fastinter for upcoming check
+        * (does nothing if fastinter is not enabled)
+        */
+       s->check.state |= CHK_ST_FASTINTER;
+
        switch (s->onerror) {
                case HANA_ONERR_FASTINTER:
                /* force fastinter - nothing to do here as all modes force it */
@@ -1285,6 +1290,10 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
                        rv -= (int) (2 * rv * (statistical_prng() / 4294967295.0));
                }
                t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(check) + rv));
+               /* reset fastinter flag (if set) so that srv_getinter()
+                * only returns fastinter if server health is degraded
+                */
+               check->state &= ~CHK_ST_FASTINTER;
        }
 
  reschedule:
index ed06687d59da284824247bffb792fc2e2f971805..0ad51b3aba5758c5537104fd8e71174a615ef9f2 100644 (file)
@@ -124,7 +124,8 @@ int srv_getinter(const struct check *check)
 {
        const struct server *s = check->server;
 
-       if ((check->state & CHK_ST_CONFIGURED) && (check->health == check->rise + check->fall - 1))
+       if ((check->state & (CHK_ST_CONFIGURED|CHK_ST_FASTINTER)) == CHK_ST_CONFIGURED &&
+           (check->health == check->rise + check->fall - 1))
                return check->inter;
 
        if ((s->next_state == SRV_ST_STOPPED) && check->health == 0)