mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-16 16:34:42 +00:00
BUG/MINOR: lua: fix extra 500ms added to socket timeouts
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.
This commit is contained in:
parent
7bb6345497
commit
7ee465f1ad
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user