From: Thierry FOURNIER Date: Fri, 4 Sep 2015 16:25:53 +0000 (+0200) Subject: BUG/MEDIUM: lua: outgoing connection was broken since 1.6-dev2 (bis) X-Git-Tag: v1.6-dev5~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=316e3196285b89a917c7d84794ced59a6a5b4eba;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: lua: outgoing connection was broken since 1.6-dev2 (bis) See commit id bdc97a8795c52af94683db25a4984578e26f4857 Michael Ezzell reported that the following Lua code fails in dev4 when the TCP is not established immediately (due to a little bit of latency): function tricky_socket() local sock = core.tcp(); sock:settimeout(3); core.log(core.alert,"calling connect()\n"); local connected, con_err = sock:connect("x.x.x.x",80); core.log(core.alert,"returned from connect()\n"); if con_err ~= nil then core.log(core.alert,"connect() failed with error: '" .. con_err .. "'\n"); end The problem is that the flags who want to wake up the applet are resetted before each applet call, so the applet must set again the flags if the connection is not established. --- diff --git a/src/hlua.c b/src/hlua.c index 61e28d0014..1e4d47c31e 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -1461,8 +1461,14 @@ static void hlua_socket_handler(struct appctx *appctx) return; } - if (!(c->flags & CO_FL_CONNECTED)) + /* if the connection is not estabkished, inform the stream that we want + * to be notified whenever the connection completes. + */ + if (!(c->flags & CO_FL_CONNECTED)) { + si_applet_cant_get(si); + si_applet_cant_put(si); return; + } /* This function is called after the connect. */ appctx->ctx.hlua.connected = 1;