Hi Adis,

On 10/17/2017 05:48 PM, Emeric Brun wrote:
> Hi Adis,
> 
> On 10/17/2017 05:41 PM, Adis Nezirovic wrote:
>> Hello guys,
>>
>> After this commit:
>>
>>   commit 0194897e540cec67d7d1e9281648b70efe403f08
>>   Author: Emeric Brun <[email protected]>
>>   Date:   Thu Mar 30 15:37:25 2017 +0200
>>
>>       MAJOR: task: task scheduler rework.
>>
>> basic Lua tasks don't work anymore.
>> e.g. this only gets called once:
>>
>>   function cron()
>>       while true do
>>           core.Debug("Hello from Cron")
>>           core.sleep(1)
>>       end
>>   end
>>   core.register_task(cron)
>>
>> ----
>>
>> The current code in task_wakeup() checks for TASK_RUNNING and decides
>> that it won't call __task_wakeup(), but when Lua task wakes up, it has
>> both, TASK_WOKEN_TIMER and TASK_RUNNING set.
>>
>> My quick fix/workaround was to add an additional check:
>>
>>   if (unlikely(!(t->state & TASK_WOKEN_TIMER) &&
>>                (t->state & TASK_RUNNING)))
>>
>> But I might be missing something more fundamental (i.e. this is really
>> necessary for multithreaded stuff), maybe we need additional flags when
>> running task_wakeup from task handlers or threads.
>>
>>
>> Best regards,
>> Adis
>>
> 
> I'm adding the haproxy's LUA engine maintainer in CC, Thierry.
> 
> He should be helpful.
> 
> R,
> Emeric
> 

This patch should fix the issue more consistently.

Could you confirm?

R,
Emeric
>From 03e97e72ce2736db7ec04ee76583e480fc85be75 Mon Sep 17 00:00:00 2001
From: Emeric Brun <[email protected]>
Date: Tue, 17 Oct 2017 18:58:40 +0200
Subject: [PATCH] BUG/MAJOR: lua: scheduled task is freezing.

Since commit 'MAJOR: task: task scheduler rework'
0194897e540cec67d7d1e9281648b70efe403f08. LUA's
scheduling tasks are freezing.

A running task should not handle the scheduling itself
but let the task scheduler to handle it based on the
'expire' field.
---
 src/hlua.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/hlua.c b/src/hlua.c
index c68495b..7eddda8 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -5360,12 +5360,6 @@ static struct task *hlua_process_task(struct task *task)
 	struct hlua *hlua = task->context;
 	enum hlua_exec status;
 
-	/* We need to remove the task from the wait queue before executing
-	 * the Lua code because we don't know if it needs to wait for
-	 * another timer or not in the case of E_AGAIN.
-	 */
-	task_delete(task);
-
 	/* If it is the first call to the task, we must initialize the
 	 * execution timeouts.
 	 */
@@ -5385,7 +5379,7 @@ static struct task *hlua_process_task(struct task *task)
 
 	case HLUA_E_AGAIN: /* co process or timeout wake me later. */
 		if (hlua->wake_time != TICK_ETERNITY)
-			task_schedule(task, hlua->wake_time);
+			task->expire = hlua->wake_time;
 		break;
 
 	/* finished with error. */
@@ -5394,6 +5388,7 @@ static struct task *hlua_process_task(struct task *task)
 		hlua_ctx_destroy(hlua);
 		task_delete(task);
 		task_free(task);
+		task = NULL;
 		break;
 
 	case HLUA_E_ERR:
@@ -5402,9 +5397,10 @@ static struct task *hlua_process_task(struct task *task)
 		hlua_ctx_destroy(hlua);
 		task_delete(task);
 		task_free(task);
+		task = NULL;
 		break;
 	}
-	return NULL;
+	return task;
 }
 
 /* This function is an LUA binding that register LUA function to be
-- 
2.7.4

Reply via email to