Willy,

Here is a patch to fix a bug recently reported by Pieter in the lua part (in the thread ".1.9dev LUA core.tcp() cannot be used from different threads").

Thanks,
--
Christopher Faulet
>From b38e9bdf727073a6063f1c56f173a247969c6f9e Mon Sep 17 00:00:00 2001
From: Christopher Faulet <[email protected]>
Date: Wed, 25 Apr 2018 10:34:45 +0200
Subject: [PATCH] BUG/MINOR: lua/threads: Make lua's tasks 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 da5611065..32199c964 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