]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: check: use atomic for s->consecutive_errors
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 7 Dec 2022 13:27:42 +0000 (14:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Dec 2022 16:04:08 +0000 (17:04 +0100)
Properly use atomic operations when dealing with s->consecutive_errors as
we're using it out of server's lock.

Race is negligible, no backport needed.

src/check.c

index 931829fb524897837c1dcefbbd95b21aa09dd02f..0f7d198597b3d90335129a34a88e22bcd6237958 100644 (file)
@@ -511,7 +511,7 @@ void set_server_check_status(struct check *check, short status, const char *desc
 
                /* clear consecutive_errors if observing is enabled */
                if (s->onerror)
-                       s->consecutive_errors = 0;
+                       HA_ATOMIC_STORE(&s->consecutive_errors, 0);
                break;
 
        default:
@@ -656,17 +656,15 @@ void __health_adjust(struct server *s, short status)
 
        if (!failed) {
                /* good: clear consecutive_errors */
-               s->consecutive_errors = 0;
+               HA_ATOMIC_STORE(&s->consecutive_errors, 0);
                return;
        }
 
-       _HA_ATOMIC_INC(&s->consecutive_errors);
-
-       if (s->consecutive_errors < s->consecutive_errors_limit)
+       if (HA_ATOMIC_ADD_FETCH(&s->consecutive_errors, 1) < s->consecutive_errors_limit)
                return;
 
        chunk_printf(&trash, "Detected %d consecutive errors, last one was: %s",
-                    s->consecutive_errors, get_analyze_status(status));
+                    HA_ATOMIC_LOAD(&s->consecutive_errors), get_analyze_status(status));
 
        HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
 
@@ -709,7 +707,7 @@ void __health_adjust(struct server *s, short status)
 
        HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
 
-       s->consecutive_errors = 0;
+       HA_ATOMIC_STORE(&s->consecutive_errors, 0);
        _HA_ATOMIC_INC(&s->counters.failed_hana);
 
        if (s->check.fastinter) {