Le 25/04/2018 à 09:26, Thierry Fournier a écrit :
Hi Pieter,

Note: The word “task" have sense in HAProxy architecture, and in Lua 
terminology. Its not
easy to write an explanation. So, the task used by Lua will be called "Lua task"

This error is unexpected. It is produced when Lua socket is started on a thread 
an continue
its execution on other thread. Technically, the core.tcp() creates a fake proxy 
to manage
the tcp connexion. This proxy is attached to a task, and the task is attached 
to a thread.
This thread must be the same than the thread of Lua Task.

The task which process HTTP or TCP trafic are sticky to one thread. But, the 
Lua task ...
no. The patch seems easy to write, but I’m afraid by the context.

For Christopher. I need an advisor :-)

In the file hlua.c at line 5602, I start a task with the value 
MAX_THREADS_MASK. I must
fix one thread, but sometimes this code is executed before effective starting, 
and before
start of thre

Oh, these tasks can be created before the threads creation... Ok, so maybe the right way to fix the bug is to registered these tasks without specific affinity and set it on the current thread the first time the tasks are woken up.

Here is an updated (and untested) patch. Pieter, could you check it please ?

Thierry, is there any way to create cosockets and applets from outside a lua's task and then manipulate them in the task's context ?

--
Christopher Faulet
>From 2996582f5c7d7878767b5972621e0fb0badc7ab5 Mon Sep 17 00:00:00 2001
From: Christopher Faulet <cfau...@haproxy.com>
Date: Wed, 25 Apr 2018 10:34:45 +0200
Subject: [PATCH] BUG/MINOR: lua/threads: Make tasks registered in lua sticky
 to the current thread

PiBa-NL reported a bug with tasks registered in lua when HAProxy is started with
serveral threads. These tasks have not specific affinity with threads so they
can be woken up on any threads. So, it is impossbile for these tasks to handled
cosockets or applets, because cosockets and applets are sticky on the thread
which created them. It is forbbiden to manipulate a cosocket from another
thread.

So to fix the bug, tasks registered in lua are now sticky to the current
thread. Because these tasks can be registered before threads creation, the
affinity is set the first time a lua's task is processed.

This patch must be backported in HAProxy 1.8.
---
 src/hlua.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/hlua.c b/src/hlua.c
index 60cf8f948..27449e37e 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -5529,6 +5529,9 @@ static struct task *hlua_process_task(struct task *task)
 	struct hlua *hlua = task->context;
 	enum hlua_exec status;
 
+	if (task->thread_mask == MAX_THREADS_MASK)
+		task_set_affinity(task, tid_bit);
+
 	/* If it is the first call to the task, we must initialize the
 	 * execution timeouts.
 	 */
-- 
2.14.3

Reply via email to