]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lua: fix wakeup condition from sleep()
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 14:12:31 +0000 (16:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 14:26:51 +0000 (16:26 +0200)
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.

src/hlua.c

index 4ccd8c57b1641e80b5f830f8c728d51176fc83e1..02dffe7d75298e2b000fca39a976eb7edcaa53f0 100644 (file)
@@ -8052,7 +8052,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;
 }