Le 12/08/2018 à 18:21, Sachin Shetty a écrit :
Hi Cyril,

I have created a very simple config to reproduce this. This config always read timesout in 9 seconds.

I think there are 3 issues.

[...]
function get_from_gds(key)
[...]     local sock = core.tcp()
     -- Connect timeout after patch
     sock:settimeout(3)
     local result = DOMAIN_NOT_FOUND
     local status, error = sock:connect(gds_host, gds_port)
     if not status then
         core.Alert("Error in connecting:" .. key .. ":" .. error)
         return "Error", "Error: " .. error
     end
     sock:settimeout(2)
     sock:send(key .. "\r\n")
     while true do
         local s, status, partial = sock:receive("*l")

1. The first one is in the LUA code, where you don't check the return code after calling sock:receive(). In this case, you enter in an "infinite" loop, adding an extra time to the response almost equal to tune.lua.session-timeout (4s by default).
You may want to add this :
        if not s then
            core.Alert("Error reading:" .. status)
            return "Error", status
        end

Now, 2 other issues seems to be in haproxy, but I'm not sure if it's the right way to fix this (I add Willy and Thierry to the thread) : 2. hlua_socket_settimeout() initializes rto/wto values, maybe it should also compute the rex/wex values :
        socket->s->req.rex = tick_add_ifset(now_ms, tmout);
        socket->s->req.wex = tick_add_ifset(now_ms, tmout);
        socket->s->res.rex = tick_add_ifset(now_ms, tmout);
        socket->s->res.wex = tick_add_ifset(now_ms, tmout);
3. It may require to wake up the task if a new timeout is set after a first one was already set (in your case the task doesn't wake up after 2 secondes because a first timeout was set to 3 seconds) :
        task_wakeup(socket->s->task, TASK_WOKEN_OTHER);

At least, it seems to fix the issue but before sending a patch, I want to be sure that's how we should fix this.

--
Cyril Bonté

Reply via email to