]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: checks: only trigger a DNS resolution with the resolvers lock
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 18 Nov 2026 13:06:45 +0000 (14:06 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 18 Nov 2026 13:08:54 +0000 (14:08 +0100)
When a health check fails to establish its L4 connection, the check code
calls resolv_trigger_resolution() on the server's requester to force a
new resolution. This function reads the resolution's status, step and
last_resolution, and writes last_resolution, while these fields are
otherwise only accessed under the resolvers' lock, possibly from another
thread processing a response. At worst a resolution is triggered again
too early, causing an extra DNS query. The resolution itself cannot be
freed in the meantime since the check holds the server's lock, which the
unlinking paths take before releasing the resolution.

The resolvers take the server's lock under their own lock, so we cannot
wait for the resolvers' lock here. The trigger being opportunistic, let's
just try to take it and skip the trigger when it is busy.

No backport is needed.

src/check.c

index 2d7d963a637bab1afc39f6105632f135b54150e2..53c8f37048e9da4d0120d9c8cdda63cf4a824a82 100644 (file)
@@ -945,9 +945,13 @@ void chk_report_conn_err(struct check *check, int errno_bck, int expired)
                /*
                 * might be due to a server IP change.
                 * Let's trigger a DNS resolution if none are currently running.
+                * Only try the lock: resolvers take the server lock under it.
                 */
-               if (check->server)
+               if (check->server && check->server->resolvers &&
+                   HA_SPIN_TRYLOCK(DNS_LOCK, &check->server->resolvers->lock) == 0) {
                        resolv_trigger_resolution(check->server->resolv_requester);
+                       HA_SPIN_UNLOCK(DNS_LOCK, &check->server->resolvers->lock);
+               }
 
        }
        else if (conn->flags & CO_FL_WAIT_L6_CONN) {