]> git.kaiwu.me - haproxy.git/commit
OPTIM: resolvers: only walk duplicates when looking up an existing record
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Sep 2026 09:07:34 +0000 (11:07 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 10 Nov 2026 14:47:52 +0000 (15:47 +0100)
commitdc537b91a62bbeda4de950fffd8909ab81d78399
tree25192395220da8e6f1ada54ab70421ec15a3b706
parenteb21fdf114238370e291c8980e762ef670d033b5
OPTIM: resolvers: only walk duplicates when looking up an existing record

When parsing answer records, resolv_validate_dns_response() looks up the
record's hash key in the answer tree to detect duplicates, then walks the
following nodes with eb32_next(), which doesn't stop at the end of the
duplicates of this key. When the key already exists but the record
differs (i.e. on a hash collision), all the remaining nodes of the tree
are compared, which is quadratic in the number of records for crafted
responses of colliding records (up to ~4000 records per 64kB TCP
response).

In normal operation the lookup returns NULL for new records and the first
node is the duplicate for repeated ones, so no difference could be
measured (60 resolutions of 4000 distinct A records over TCP cost the
same CPU time before and after). Still, let's use eb32_next_dup() to only
walk the nodes sharing the looked up key, as intended.

No backport is needed.
src/resolvers.c