net.unbound: Delay loading until server has started or first query
authorKim Alvefur <zash@zash.se>
Tue, 05 Jan 2021 21:40:06 +0100
changeset 11257 919e7b962f0b
parent 11256 ba335004ca60
child 11258 613035d6e5a0
net.unbound: Delay loading until server has started or first query Shouldn't need a DNS resolver until later anyways. Might even be sensible to only initialize if a query is actually attempted.
net/unbound.lua
--- a/net/unbound.lua	Tue Jan 05 21:36:04 2021 +0100
+++ b/net/unbound.lua	Tue Jan 05 21:40:06 2021 +0100
@@ -60,7 +60,9 @@
 	unbound = libunbound.new(unbound_config);
 	server_conn = connect_server(unbound, net_server);
 end
-initialize();
+if prosody then
+	prosody.events.add_handler("server-started", initialize);
+end
 
 local answer_mt = {
 	__tostring = function(self)
@@ -105,6 +107,7 @@
 end
 
 local function lookup(callback, qname, qtype, qclass)
+	if not unbound then initialize(); end
 	qtype = qtype and s_upper(qtype) or "A";
 	qclass = qclass and s_upper(qclass) or "IN";
 	local ntype, nclass = types[qtype], classes[qclass];