diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/server_epoll.lua | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua index fa8a482d..2841278d 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -99,8 +99,14 @@ local fds = createtable(10, 0); -- FD -> conn local timers = indexedbheap.create(); local function noop() end + +-- Keep track of recently closed timers to avoid re-adding them +local closedtimers = {}; + local function closetimer(id) - timers:remove(id); + if timers:remove(id) then + closedtimers[id] = true; + end end local function reschedule(id, time) @@ -138,7 +144,7 @@ local function runtimers(next_delay, min_wait) local _, timer, id = timers:pop(); local ok, ret = xpcall(timer, traceback, now, id); - if ok and type(ret) == "number" then + if ok and type(ret) == "number" and not closedtimers[id] then local next_time = elapsed+ret; -- Delay insertion of timers to be re-added -- so they don't get called again this tick @@ -161,6 +167,10 @@ local function runtimers(next_delay, min_wait) peek = timers:peek(); end + if next(closedtimers) ~= nil then + closedtimers = {}; + end + if peek == nil then return next_delay; else |