From: Willy Tarreau Date: Thu, 30 Sep 2021 14:12:31 +0000 (+0200) Subject: BUG/MEDIUM: lua: fix wakeup condition from sleep() X-Git-Tag: v2.3.15~62 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=3083c49;p=haproxy-2.3.git BUG/MEDIUM: lua: fix wakeup condition from sleep() A time comparison was wrong in hlua_sleep_yield(), making the sleep() code do nothing for periods of 24 days every 49 days. An arithmetic comparison was performed on now_ms instead of using tick_is_expired(). This bug was added in 1.6-dev by commit 5b8608f1e ("MINOR: lua: core: add sleep functions") so the fix should be backported to all stable versions. (cherry picked from commit 12c02701d304f29ca74f521cfcc5fe1bc6f3e03d) Signed-off-by: Christopher Faulet (cherry picked from commit 9cc2e4c9962bf83a0d08629444848f3ddae64473) Signed-off-by: Christopher Faulet --- diff --git a/src/hlua.c b/src/hlua.c index 4d48136..4778977 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -6071,7 +6071,7 @@ __LJMP static int hlua_log_alert(lua_State *L) __LJMP static int hlua_sleep_yield(lua_State *L, int status, lua_KContext ctx) { int wakeup_ms = lua_tointeger(L, -1); - if (now_ms < wakeup_ms) + if (!tick_is_expired(wakeup_ms, now_ms)) MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0)); return 0; }