From: Olivier Houchard Date: Wed, 18 Nov 2026 13:06:45 +0000 (+0100) Subject: BUG/MINOR: checks: only trigger a DNS resolution with the resolvers lock X-Git-Tag: v3.5-dev13~13 X-Git-Url: https://git.kaiwu.me/web//%22?a=commitdiff_plain;h=973c07763ef5f0c7d50b7c77fb9bcfefbc1ef997;p=haproxy.git BUG/MINOR: checks: only trigger a DNS resolution with the resolvers lock 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. --- diff --git a/src/check.c b/src/check.c index 2d7d963a6..53c8f3704 100644 --- a/src/check.c +++ b/src/check.c @@ -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) {