Software /
code /
prosody
Comparison
net/dns.lua @ 10956:03a09fa02e8e
net.dns: Fix timeout retry logic
On timeout the query would be resent twice - once within
servfail(), and again inside the timeout callback.
This commit moves all retry logic to servfail().
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 25 Jun 2020 15:28:23 +0100 |
parent | 10955:7bcfac630b65 |
child | 10957:8902cecbdd39 |
comparison
equal
deleted
inserted
replaced
10955:7bcfac630b65 | 10956:03a09fa02e8e |
---|---|
854 local o = { | 854 local o = { |
855 packet = header..question, | 855 packet = header..question, |
856 server = self.best_server, | 856 server = self.best_server, |
857 delay = 1, | 857 delay = 1, |
858 retry = socket.gettime() + self.delays[1] | 858 retry = socket.gettime() + self.delays[1] |
859 qclass = qclass; | |
860 qtype = qtype; | |
861 qname = qname; | |
859 }; | 862 }; |
860 | 863 |
861 -- remember the query | 864 -- remember the query |
862 self.active[id] = self.active[id] or {}; | 865 self.active[id] = self.active[id] or {}; |
863 self.active[id][question] = o; | 866 self.active[id][question] = o; |
876 if have_timer and self.timeout then | 879 if have_timer and self.timeout then |
877 local num_servers = #self.server; | 880 local num_servers = #self.server; |
878 local i = 1; | 881 local i = 1; |
879 timer.add_task(self.timeout, function () | 882 timer.add_task(self.timeout, function () |
880 if get(self.wanted, qclass, qtype, qname, co) then | 883 if get(self.wanted, qclass, qtype, qname, co) then |
881 if i < num_servers then | |
882 log("debug", "DNS request timeout %d/%d", i, num_servers) | 884 log("debug", "DNS request timeout %d/%d", i, num_servers) |
883 i = i + 1; | 885 i = i + 1; |
884 self:servfail(conn); | 886 self:servfail(self.socket[o.server]); |
885 o.server = self.best_server; | 887 -- end |
886 conn, err = self:getsocket(o.server); | 888 end |
887 if conn then | 889 -- Still outstanding? (i.e. retried) |
888 conn:send(o.packet); | 890 if get(self.wanted, qclass, qtype, qname, co) then |
889 return self.timeout; | 891 return self.timeout; -- Then wait |
890 end | |
891 end | |
892 -- Tried everything, failed | |
893 self:cancel(qclass, qtype, qname); | |
894 end | 892 end |
895 end) | 893 end) |
896 end | 894 end |
897 return true; | 895 return true; |
898 end | 896 end |
915 if o.server > #self.server then | 913 if o.server > #self.server then |
916 o.server = 1; | 914 o.server = 1; |
917 end | 915 end |
918 | 916 |
919 o.retries = (o.retries or 0) + 1; | 917 o.retries = (o.retries or 0) + 1; |
920 if o.retries >= #self.server then | 918 local retried; |
921 --print('timeout'); | 919 if o.retries < #self.server then |
920 sock, err = self:getsocket(o.server); | |
921 if sock then | |
922 retried = true; | |
923 log("debug", "retry %d (immediate)", o.retries); | |
924 sock:send(o.packet); | |
925 end | |
926 end | |
927 if not retried then | |
928 log("debug", 'tried all servers, giving up'); | |
929 self:cancel(o.qclass, o.qtype, o.qname); | |
922 queries[question] = nil; | 930 queries[question] = nil; |
923 else | |
924 sock, err = self:getsocket(o.server); | |
925 if sock then sock:send(o.packet); end | |
926 end | 931 end |
927 end | 932 end |
928 end | 933 end |
929 if next(queries) == nil then | 934 if next(queries) == nil then |
930 self.active[id] = nil; | 935 self.active[id] = nil; |