MINOR: hlua: Save the lua socket's timeout in its context
When the lua socket timeout is set, it is now saved in its context. If there
is already a stream attached to the appctx, the timeout is then immediately
modified. Otherwise, it is modified when the stream is created, thus during
the appctx initialization.
For now, the appctx is initialized when it is created. But this will change
to fix issues with the lua sockets. Thus, this patch is mandatory.
(cherry picked from commit 0be1ae2fa2d04584027fa09af2e3b54c0a0786b7)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
diff --git a/src/hlua.c b/src/hlua.c
index 902dc48..bf02e19 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -278,6 +278,7 @@
struct list wake_on_read;
struct list wake_on_write;
struct appctx *appctx;
+ int timeout;
int die;
};
@@ -2300,6 +2301,7 @@
static int hlua_socket_init(struct appctx *appctx)
{
+ struct hlua_csk_ctx *csk_ctx = appctx->svcctx;
struct stream *s;
if (appctx_finalize_startup(appctx, socket_proxy, &BUF_NULL) == -1)
@@ -2317,6 +2319,12 @@
s->flags |= SF_DIRECT | SF_ASSIGNED | SF_BE_ASSIGNED;
s->target = &socket_tcp->obj_type;
+ if (csk_ctx->timeout) {
+ s->sess->fe->timeout.connect = csk_ctx->timeout;
+ s->scf->ioto = csk_ctx->timeout;
+ s->scb->ioto = csk_ctx->timeout;
+ }
+
return 0;
error:
@@ -3246,6 +3254,8 @@
int tmout;
double dtmout;
struct xref *peer;
+ struct hlua_csk_ctx *csk_ctx;
+ struct appctx *appctx;
struct stream *s;
MAY_LJMP(check_args(L, 2, "settimeout"));
@@ -3280,17 +3290,25 @@
return 0;
}
- s = appctx_strm(container_of(peer, struct hlua_csk_ctx, xref)->appctx);
+ csk_ctx = container_of(peer, struct hlua_csk_ctx, xref);
+ csk_ctx->timeout = tmout;
+
+ appctx = csk_ctx->appctx;
+ if (!appctx_sc(appctx))
+ goto end;
+
+ s = appctx_strm(csk_ctx->appctx);
s->sess->fe->timeout.connect = tmout;
s->scf->ioto = tmout;
s->scb->ioto = tmout;
- s->task->expire = tick_add_ifset(now_ms, tmout);
+ s->task->expire = (tick_is_expired(s->task->expire, now_ms) ? 0 : s->task->expire);
+ s->task->expire = tick_first(s->task->expire, tick_add_ifset(now_ms, tmout));
task_queue(s->task);
+ end:
xref_unlock(&socket->xref, peer);
-
lua_pushinteger(L, 1);
return 1;
}
@@ -3333,6 +3351,7 @@
ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
ctx->connected = 0;
ctx->die = 0;
+ ctx->timeout = 0;
ctx->appctx = appctx;
LIST_INIT(&ctx->wake_on_write);
LIST_INIT(&ctx->wake_on_read);