Since commit #56cc12509, haproxy accepts double values for timeouts. The
value is then converted to  milliseconds before being round 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.

This patch is specific to the 1.9 branch and doesn't require to be
backported.
---
 src/hlua.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/hlua.c b/src/hlua.c
index 06c115561..73227b4ca 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2545,17 +2545,18 @@ __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);
+       /* round up the timeout to convert it to int */
+       tmout = MS_TO_TICKS((int)(dtmout + 0.5));
 
        /* Check if we run on the same thread than the xreator thread.
         * We cannot access to the socket if the thread is different.
-- 
2.18.0


Reply via email to