Hi,
Le 26/07/2018 à 19:54, Sachin Shetty a écrit :
Hi,
We are using a http-req lua action to dynamically set some app specific
metadata headers. The lua handler connects to a upstream memcache like
service over tcp to fetch additional metadata.
Functionally everything works ok, but I am seeing that socket.settimeout
has no effect. Irrespective of what I set in settimeout if the upstream
service is unreachable, connect always timesout at 5 seconds, and read
timeout around 10 seconds. It seems like settimeout has no effect and
it always picks defaults of 5 seconds for connect timeout and 10 seconds
for read timeout.
For the connect timeout, it seems this is a hardcoded default value in
src/hlua.c:
socket_proxy.timeout.connect = 5000; /* By default the timeout
connection is 5s. */
If it's possible, can you try the patch attached (for the 1.7.x branch)
? But please don't use it in production yet ;-)
Haproxy conf call:
http-request lua.get_proxy
Lua code sample:
function get_proxy(txn)
local sock = core.tcp()
sock:settimeout(2)
status, error = sock:connect(gds_host, gds_port)
if not status then
core.Alert("1 Error in connecting:" .. key .. ":" .. error)
return result, "Error: " .. error
end
sock:send(key .. "\r\n")
....
....
core.register_action("get_proxy", { "http-req" }, get_proxy)
Haproxy version:
HA-Proxy version 1.7.8 2017/07/07
Copyright 2000-2017 Willy Tarreau <wi...@haproxy.org
<mailto:wi...@haproxy.org>>
Build options :
TARGET = linux2628
CPU = generic
CC = gcc
CFLAGS = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement
-fwrapv -DTCP_USER_TIMEOUT=18
OPTIONS = USE_LINUX_TPROXY=1 USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1
USE_LUA=1 USE_PCRE=1
Default settings :
maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Encrypted password support via crypt(3): yes
Built with zlib version : 1.2.7
Running on zlib version : 1.2.7
Compression algorithms supported : identity("identity"),
deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with OpenSSL version : OpenSSL 1.0.1e-fips 11 Feb 2013
Running on OpenSSL version : OpenSSL 1.0.1e-fips 11 Feb 2013
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports prefer-server-ciphers : yes
Built with PCRE version : 8.32 2012-11-30
Running on PCRE version : 8.32 2012-11-30
PCRE library supports JIT : no (USE_PCRE_JIT not set)
Built with Lua version : Lua 5.3.2
Built with transparent proxy support using: IP_TRANSPARENT
IPV6_TRANSPARENT IP_FREEBIND
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available filters :
[COMP] compression
[TRACE] trace
[SPOE] spoe
Thanks
Sachin
--
Cyril Bonté
diff --git a/src/hlua.c b/src/hlua.c
index 874a4acc..10cf845e 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2286,6 +2286,7 @@ __LJMP static int hlua_socket_settimeout(struct lua_State *L)
if (tmout < 0)
WILL_LJMP(luaL_error(L, "settimeout: cannot set negatives values"));
+ socket->s->sess->fe->timeout.connect = tmout;
socket->s->req.rto = tmout;
socket->s->req.wto = tmout;
socket->s->res.rto = tmout;