aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-03-21 11:01:58 +0000
committerMatthew Wild <mwild1@gmail.com>2022-03-21 11:01:58 +0000
commitb42fe8746c442351e0330c4570b0ae7eba102fe8 (patch)
tree32739648546517cf46867c1aa39855120904cf25
parentcc40d15df7fd89acc7d3fc563220dd163743e811 (diff)
downloadprosody-b42fe8746c442351e0330c4570b0ae7eba102fe8.tar.gz
prosody-b42fe8746c442351e0330c4570b0ae7eba102fe8.zip
net.connect: Improve handling of failure when attempts are still pending
This could lead to failure being reported too early, even if some connections have not yet failed.
-rw-r--r--net/connect.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/net/connect.lua b/net/connect.lua
index 241cc65b..0ae9c2b2 100644
--- a/net/connect.lua
+++ b/net/connect.lua
@@ -33,8 +33,13 @@ local function attempt_connection(p)
if not conn_type then
-- No more 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 p.target_resolver.last_error or "unable to resolve service");
+ if next(p.conns) == nil then
+ p:log("debug", "No more targets, no pending connections. Connection failed.");
+ if p.listeners.onfail then
+ p.listeners.onfail(p.data, p.last_error or p.target_resolver.last_error or "unable to resolve service");
+ end
+ else
+ p:log("debug", "One or more connection attempts are still pending. Waiting for now.");
end
return;
end
@@ -88,7 +93,10 @@ function pending_connection_listeners.ondisconnect(conn, reason)
p.conns[conn] = nil;
p.last_error = reason or "unknown reason";
p:log("debug", "Connection attempt failed: %s", p.last_error);
- attempt_connection(p);
+ if next(p.conns) == nil and not p.connected then
+ p:log("debug", "No pending connection attempts, and not yet connected");
+ attempt_connection(p);
+ end
end
local function connect(target_resolver, listeners, options, data)