diff options
author | Kim Alvefur <zash@zash.se> | 2021-08-31 13:34:08 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-08-31 13:34:08 +0200 |
commit | 307e58cc75eda7aa9b7bef4d65d7952b6bca8748 (patch) | |
tree | 8d49c142bab1d8896e11e063abe65f02e29da74f /net/server_epoll.lua | |
parent | 9eb707763c5b867b30f805f40eb979bf04001afc (diff) | |
download | prosody-307e58cc75eda7aa9b7bef4d65d7952b6bca8748.tar.gz prosody-307e58cc75eda7aa9b7bef4d65d7952b6bca8748.zip |
net.server_epoll: Prevent removed timers from being readded
In a case like this the timer would not be readded:
addtimer(1, function(t, id)
stop(id)
return 1
end);
Diffstat (limited to 'net/server_epoll.lua')
-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 |