]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: schedule socket task upon lua connect()
authorPiBa-NL <PiBa.NL.dev@gmail.com>
Sat, 5 May 2018 21:51:42 +0000 (23:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 6 May 2018 12:36:41 +0000 (14:36 +0200)
The parameters like server-address, port and timeout should be set before
process_stream task is called to avoid the stream being 'closed' before it
got initialized properly. This is most clearly visible when running with
tune.lua.forced-yield=1.. So scheduling the task should not be done when
creating the lua socket, but when connect is called. The error
"socket: not yet initialised, you can't set timeouts." would then appear.

Below code for example also shows this issue, as the sleep will
yield the lua code:
  local con = core.tcp()
  core.sleep(1)
  con:settimeout(10)

src/hlua.c

index 4c56409cb4f17be0060257d71026559ddf505cc4..d07e8d675eac2627970bc1ccd9c5fcfff5db8171 100644 (file)
@@ -2423,6 +2423,10 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
                WILL_LJMP(luaL_error(L, "out of memory"));
        }
        xref_unlock(&socket->xref, peer);
+
+       task_wakeup(s->task, TASK_WOKEN_INIT);
+       /* Return yield waiting for connection. */
+
        WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));
 
        return 0;
@@ -2582,8 +2586,6 @@ __LJMP static int hlua_socket_new(lua_State *L)
        strm->flags |= SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET | SF_BE_ASSIGNED;
        strm->target = &socket_tcp.obj_type;
 
-       task_wakeup(strm->task, TASK_WOKEN_INIT);
-       /* Return yield waiting for connection. */
        return 1;
 
  out_fail_stream: