net.server_epoll: Catch errors from luasec.wrap
authorKim Alvefur <zash@zash.se>
Fri, 14 Sep 2018 01:31:26 +0200
changeset 9434 c3c0523a37c6
parent 9433 412ff404bf58
child 9435 2e3f66475cc8
net.server_epoll: Catch errors from luasec.wrap It throws if given an invalid TLS context
net/server_epoll.lua
--- a/net/server_epoll.lua	Fri Sep 14 01:34:38 2018 +0200
+++ b/net/server_epoll.lua	Fri Sep 14 01:31:26 2018 +0200
@@ -463,7 +463,11 @@
 		self._tls = true;
 		log("debug", "Start TLS on %s now", self);
 		self:del();
-		local conn, err = luasec.wrap(self.conn, self.tls_ctx);
+		local ok, conn, err = pcall(luasec.wrap, self.conn, self.tls_ctx);
+		if not ok then
+			log("error", "Failed to initialize TLS: %s", conn);
+			conn, err = ok, conn;
+		end
 		if not conn then
 			self:on("disconnect", err);
 			self:destroy();