Comparison

net/server_epoll.lua @ 10586:f86ed818a7f8

net.server_epoll: Collect full traceback from errors in listeners
author Kim Alvefur <zash@zash.se>
date Sun, 05 Jan 2020 02:29:31 +0100
parent 10571:cfeb0077c9e9
child 10587:863aa36a9dd8
comparison
equal deleted inserted replaced
10585:2d8535338099 10586:f86ed818a7f8
11 local setmetatable = setmetatable; 11 local setmetatable = setmetatable;
12 local pcall = pcall; 12 local pcall = pcall;
13 local type = type; 13 local type = type;
14 local next = next; 14 local next = next;
15 local pairs = pairs; 15 local pairs = pairs;
16 local traceback = debug.traceback;
16 local logger = require "util.logger"; 17 local logger = require "util.logger";
17 local log = logger.init("server_epoll"); 18 local log = logger.init("server_epoll");
18 local socket = require "socket"; 19 local socket = require "socket";
19 local luasec = require "ssl"; 20 local luasec = require "ssl";
20 local realtime = require "util.time".now; 21 local realtime = require "util.time".now;
23 local createtable = require "util.table".create; 24 local createtable = require "util.table".create;
24 local inet = require "util.net"; 25 local inet = require "util.net";
25 local inet_pton = inet.pton; 26 local inet_pton = inet.pton;
26 local _SOCKETINVALID = socket._SOCKETINVALID or -1; 27 local _SOCKETINVALID = socket._SOCKETINVALID or -1;
27 local new_id = require "util.id".medium; 28 local new_id = require "util.id".medium;
29 local xpcall = require "util.xpcall".xpcall;
28 30
29 local poller = require "util.poll" 31 local poller = require "util.poll"
30 local EEXIST = poller.EEXIST; 32 local EEXIST = poller.EEXIST;
31 local ENOENT = poller.ENOENT; 33 local ENOENT = poller.ENOENT;
32 34
173 local listener = self.listeners["on"..what]; 175 local listener = self.listeners["on"..what];
174 if not listener then 176 if not listener then
175 -- self:debug("Missing listener 'on%s'", what); -- uncomment for development and debugging 177 -- self:debug("Missing listener 'on%s'", what); -- uncomment for development and debugging
176 return; 178 return;
177 end 179 end
178 local ok, err = pcall(listener, self, ...); 180 local ok, err = xpcall(listener, traceback, self, ...);
179 if not ok then 181 if not ok then
180 if cfg.fatal_errors then 182 if cfg.fatal_errors then
181 self:debug("Closing due to error calling on%s: %s", what, err); 183 self:debug("Closing due to error calling on%s: %s", what, err);
182 self:destroy(); 184 self:destroy();
183 else 185 else