mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
net.connect: Propagate last error message from resolvers
Previously it would only say "unable to resolve server" for all DNS problems. While "NoError in A lookup" might not make much sense to users, it should help in debugging more than the previous generic error. Friendlier errors will be future work.
This commit is contained in:
parent
30ef01a6cc
commit
93121127fa
3 changed files with 28 additions and 5 deletions
|
@ -35,9 +35,9 @@ local function attempt_connection(p)
|
|||
p.target_resolver:next(function (conn_type, ip, port, extra)
|
||||
if not conn_type then
|
||||
-- No more targets to try
|
||||
p:log("debug", "No more connection targets to try");
|
||||
p:log("debug", "No more connection targets to try", p.target_resolver.last_error);
|
||||
if p.listeners.onfail then
|
||||
p.listeners.onfail(p.data, p.last_error or "unable to resolve service");
|
||||
p.listeners.onfail(p.data, p.target_resolver.last_error or p.last_error or "unable to resolve service");
|
||||
end
|
||||
return;
|
||||
end
|
||||
|
|
|
@ -52,12 +52,17 @@ function methods:next(cb)
|
|||
local dns_resolver = adns.resolver();
|
||||
|
||||
if not self.extra or self.extra.use_ipv4 ~= false then
|
||||
dns_resolver:lookup(function (answer)
|
||||
dns_resolver:lookup(function (answer, err)
|
||||
if answer then
|
||||
secure = secure and answer.secure;
|
||||
for _, record in ipairs(answer) do
|
||||
table.insert(targets, { self.conn_type.."4", record.a, self.port, self.extra });
|
||||
end
|
||||
if answer.status then
|
||||
self.last_error = answer.status .. " in A lookup";
|
||||
end
|
||||
else
|
||||
self.last_error = err;
|
||||
end
|
||||
ready();
|
||||
end, self.hostname, "A", "IN");
|
||||
|
@ -66,12 +71,17 @@ function methods:next(cb)
|
|||
end
|
||||
|
||||
if not self.extra or self.extra.use_ipv6 ~= false then
|
||||
dns_resolver:lookup(function (answer)
|
||||
dns_resolver:lookup(function (answer, err)
|
||||
if answer then
|
||||
secure = secure and answer.secure;
|
||||
for _, record in ipairs(answer) do
|
||||
table.insert(targets, { self.conn_type.."6", record.aaaa, self.port, self.extra });
|
||||
end
|
||||
if answer.status then
|
||||
self.last_error = answer.status .. " in AAAA lookup";
|
||||
end
|
||||
else
|
||||
self.last_error = err;
|
||||
end
|
||||
ready();
|
||||
end, self.hostname, "AAAA", "IN");
|
||||
|
@ -80,12 +90,17 @@ function methods:next(cb)
|
|||
end
|
||||
|
||||
if self.extra and self.extra.use_dane == true then
|
||||
dns_resolver:lookup(function (answer)
|
||||
dns_resolver:lookup(function (answer, err)
|
||||
if answer then
|
||||
secure = secure and answer.secure;
|
||||
for _, record in ipairs(answer) do
|
||||
table.insert(tlsa, record.tlsa);
|
||||
end
|
||||
if answer.status then
|
||||
self.last_error = answer.status .. " in TLSA lookup";
|
||||
end
|
||||
else
|
||||
self.last_error = err;
|
||||
end
|
||||
ready();
|
||||
end, ("_%d._tcp.%s"):format(self.port, self.hostname), "TLSA", "IN");
|
||||
|
|
|
@ -20,6 +20,9 @@ function methods:next(cb)
|
|||
self.resolver = basic.new(unpack(next_target, 1, 4));
|
||||
end
|
||||
self.resolver:next(function (...)
|
||||
if self.resolver then
|
||||
self.last_error = self.resolver.last_error;
|
||||
end
|
||||
if ... == nil then
|
||||
self.resolver = nil;
|
||||
self:next(cb);
|
||||
|
@ -57,12 +60,15 @@ function methods:next(cb)
|
|||
if #answer == 0 then
|
||||
if self.extra and self.extra.default_port then
|
||||
table.insert(targets, { self.hostname, self.extra.default_port, self.conn_type, self.extra });
|
||||
else
|
||||
self.last_error = "zero SRV records found";
|
||||
end
|
||||
ready();
|
||||
return;
|
||||
end
|
||||
|
||||
if #answer == 1 and answer[1].srv.target == "." then -- No service here
|
||||
self.last_error = "service explicitly unavailable";
|
||||
ready();
|
||||
return;
|
||||
end
|
||||
|
@ -71,6 +77,8 @@ function methods:next(cb)
|
|||
for _, record in ipairs(answer) do
|
||||
table.insert(targets, { record.srv.target, record.srv.port, self.conn_type, self.extra });
|
||||
end
|
||||
else
|
||||
self.last_error = err;
|
||||
end
|
||||
ready();
|
||||
end, "_" .. self.service .. "._" .. self.conn_type .. "." .. self.hostname, "SRV", "IN");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue