# HG changeset patch # User Kim Alvefur # Date 1470954319 -7200 # Node ID 3a2fe8e10eebe2142595d0c0aa74c937f0a114c9 # Parent f0dd902534b0dbac97744fb2419fab3b172963b6 net.server_epoll: Fix calculation of next timer event diff -r f0dd902534b0 -r 3a2fe8e10eeb net/server_epoll.lua --- a/net/server_epoll.lua Thu Aug 11 22:49:26 2016 +0200 +++ b/net/server_epoll.lua Fri Aug 12 00:25:19 2016 +0200 @@ -79,24 +79,22 @@ if diff < next_delay then next_delay = diff; end - return next_delay; + break; end local new_timeout = f(now); if new_timeout then - local t_diff = t + new_timeout - now; - if t_diff < 1e-6 then - t_diff = 1e-6; - end - if t_diff < next_delay then - next_delay = t_diff; - end timer[1] = t + new_timeout; resort_timers = true; else t_remove(timers, i); end end - if next_delay < 1e-6 then + if resort_timers or next_delay < 1e-6 then + -- Timers may be added from within a timer callback. + -- Those would not be considered for next_dela, + -- and we might sleep for too long, so instead + -- we return a shorter timeout so we can + -- properly sort all new timers. next_delay = 1e-6; end return next_delay;