Changeset

9587:42eedef517dc

net.server_epoll: Reschedule delayed timers relative to current time This should normally never happen, but can be reproduced by suspending the process a while.
author Kim Alvefur <zash@zash.se>
date Sun, 28 Oct 2018 18:22:17 +0100
parents 9586:44dbee2f173f
children 9594:dcf466e04f81
files net/server_epoll.lua
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_epoll.lua	Sun Oct 28 17:17:07 2018 +0100
+++ b/net/server_epoll.lua	Sun Oct 28 18:22:17 2018 +0100
@@ -106,9 +106,13 @@
 		end
 		local new_timeout = f(now);
 		if new_timeout then
-			-- Schedule for 'delay' from the time actually scheduled,
-			-- not from now, in order to prevent timer drift.
-			timer[1] = t + new_timeout;
+			-- Schedule for 'delay' from the time actually scheduled, not from now,
+			-- in order to prevent timer drift, unless it already drifted way out of sync.
+			if (t + new_timeout) > ( now - new_timeout ) then
+				timer[1] = t + new_timeout;
+			else
+				timer[1] = now + new_timeout;
+			end
 			resort_timers = true;
 		else
 			t_remove(timers, i);