I was re-reading the libravatar specification today, and noticed that I had missed a section that described what to do if a DNS query results in multiple records. The current implementation just used a "simple" (dns-query ...) but that is explicit not sufficient. Instead one must choose the highest priority servers and then randomly select one of these, according to their weights. The patch I have attached to this mail implements this, and can be tested by evaluating (gravatar--service-libravatar "test@pusling.com") It's rather hard to find a domain with multiple libravatar entries, but the selection algorithm can be tested using this slightly modified excerpt from the patch: (defun test-selection () (catch 'found ;; res is a hardcoded and simplified (dns-query "..." t) result. ;; "target" would usually point to a domain. (let* ((res '(((target alpha) (priority 10) (weight 10)) ((target beta) (priority 10) (weight 0)) ((target gamma) (priority 10) (weight 30)) ((target delta) (priority 5) (weight 10)))) (prio (mapcar (lambda (r) (dns-get 'priority r)) res)) (max (apply #'max prio)) (sum 0) top) (dolist (rec res) (when (= max (dns-get 'priority rec)) (setq sum (+ sum (dns-get 'weight rec))) (push rec top))) (dolist (rec top) (when (<= (if (= 0 sum) -1 (random sum)) (dns-get 'weight rec)) (throw 'found (dns-get 'target rec))) (setq sum (- sum (dns-get 'weight rec))))))) (/ (cl-loop repeat 1000 count (eq (test-selection) 'gamma)) 1000.0) where the last expression should approximately equal 0.75 (3/4), because only the records alpha, beta and gamma have the highest priority (10), and between them gamma has a 30/(10 + 30) = 3/4'th chance of being chosen. In case all records are weighted 0, the first one is chosen. I once again apologise for not thoroughly enough testing my last patch, and hope this at least somewhat makes up for it. -- Philip K.