]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: resolvers: preserve nameserver identity on "clear counters all"
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Sep 2026 07:28:02 +0000 (09:28 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 10 Nov 2026 14:47:52 +0000 (15:47 +0100)
The resolvers statistics module stores the nameserver's id, its parent
resolvers' id and the nameserver's puid in the counters structure, next
to the counters themselves. "clear counters all" resets all counters by
copying the module's template over them in resolv_stats_clear_counters(),
which also clears these fields. As a result, "show stat domain resolvers"
reports empty "id" and "pid" fields for all nameservers afterwards, and
ns_puid becomes zero, so that server address changes performed by a DNS
resolution are then attributed to the wrong nameserver
(SERVER_INETADDR_UPDATER_DNS_RESOLVER(counters->ns_puid)).

This can be reproduced with any resolvers section:

  > clear counters all
  > show stat domain resolvers
  # id,pid,sent,...
  ,,0,0,...

Let's restore these fields after the reset, as done when allocating the
counters.

This patch should be backported to all stable branches.

src/resolvers.c

index 67726b035647af212e1e734831faa4c2f78a5ce9..addc98836a1365769bc4f1654f04ac92a5770393 100644 (file)
@@ -3094,6 +3094,13 @@ void resolv_stats_clear_counters(int clrall, struct list *stat_modules)
                        list_for_each_entry(ns, &resolvers->nameservers, list) {
                                counters = EXTRA_COUNTERS_GET(ns->extra_counters, mod);
                                memcpy(counters, mod->counters, mod->counters_size);
+
+                               /* restore the identity fields which are not counters */
+                               if (mod == &rslv_stats_module) {
+                                       ns->counters->id = ns->id;
+                                       ns->counters->ns_puid = ns->puid;
+                                       ns->counters->pid = resolvers->id;
+                               }
                        }
                }
        }