Changeset

8547:5e9c87376891

net.connect: Handle case when resolver runs out of targets
author Matthew Wild <mwild1@gmail.com>
date Mon, 26 Feb 2018 15:21:27 +0000
parents 8546:d66916dc318a
children 8548:162f75ac2693
files net/connect.lua
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/net/connect.lua	Mon Feb 26 15:20:35 2018 +0000
+++ b/net/connect.lua	Mon Feb 26 15:21:27 2018 +0000
@@ -27,6 +27,14 @@
 		p.conn = nil;
 	end
 	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");
+			if p.listeners.onfail then
+				p.listeners.onfail(p.data, p.last_error or "unable to connect to service");
+			end
+			return;
+		end
 		p:log("debug", "Next target to try is %s:%d", ip, port);
 		local conn = assert(server.addclient(ip, port, pending_connection_listeners, p.options.pattern or "*a", p.options.sslctx, conn_type, extra));
 		p.conn = conn;