]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: fix extra 500ms added to socket timeouts
authorCyril Bonté <cyril.bonte@free.fr>
Sun, 19 Aug 2018 20:08:50 +0000 (22:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 19 Aug 2018 20:11:28 +0000 (22:11 +0200)
Since commit #56cc12509, haproxy accepts double values for timeouts. The
value is then converted to  milliseconds before being rounded up and cast
to int. The issue is that to round up the value, a constant value of 0.5
is added to it, but too early in the conversion, resulting in an
additional 500ms to the value. We are talking about a precision of 1ms,
so we can safely get rid of this rounding trick and adjust resulting
timeouts equal to 0 to a minimum of 1ms.

This patch is specific to the 1.9 branch and doesn't require to be
backported.

src/hlua.c

index 06c1155611993f734ae136282f4763fccf5a7dce..65986473a0d13bafefd8ae6b70c7ac399247a590 100644 (file)
@@ -2545,17 +2545,19 @@ __LJMP static int hlua_socket_settimeout(struct lua_State *L)
 
        socket = MAY_LJMP(hlua_checksocket(L, 1));
 
-       /* round up for inputs that are fractions and convert to millis */
-       dtmout = (0.5 + MAY_LJMP(luaL_checknumber(L, 2))) * 1000;
+       /* convert the timeout to millis */
+       dtmout = MAY_LJMP(luaL_checknumber(L, 2)) * 1000;
 
        /* Check for negative values */
        if (dtmout < 0)
                WILL_LJMP(luaL_error(L, "settimeout: cannot set negatives values"));
 
        if (dtmout > INT_MAX) /* overflow check */
-               WILL_LJMP(luaL_error(L, "settimeout: cannot set values larger than %d", INT_MAX));
+               WILL_LJMP(luaL_error(L, "settimeout: cannot set values larger than %d ms", INT_MAX));
 
        tmout = MS_TO_TICKS((int)dtmout);
+       if (tmout == 0)
+               tmout++; /* very small timeouts are adjusted to a minium of 1ms */
 
        /* Check if we run on the same thread than the xreator thread.
         * We cannot access to the socket if the thread is different.