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 threads. Maybe, if “tid” is no set, using 0x01, or random bit ? This is ugly... Any idea ? Pieter: I attach a temporary patch just for validating the source of the problem. Could you try it ? BR, Thierry
0001-TEMP-BUG-MINOR-Lua-Task-are-not-attached-to-a-thread.patch
Description: Binary data
> On 23 Apr 2018, at 23:07, PiBa-NL <[email protected]> wrote: > > Hi List, Thierry (LUA maintainer), Christopher (Multi-Threading), > > When im making a tcp connection to a (mail) server from a lua task this error > pops up randomly when using 'nbthread 4', the error luckily seems pretty self > explanatory, but ill leave that to the threading and lua experts to come up > with a fix ;) i think somehow the script or at least its socket commands must > be forced to always be executed on the same thread? or perhaps there is > another way.. > > Also i do wonder how far lua is safe to use at all in a multithreaded > program. Or would that become impossible to keep safe.?. But thats a bit > offtopic perhaps.. > > Line 240: recieve = mailer.receive(mailer, "*l") > [ALERT] 110/232212 (678) : Lua task: runtime error: > /root/haproxytest/test.lua:240: connect: cannot use socket on other thread. > > Line 266: local mailer = core.tcp() > Line 267: ret = mailer.connect(mailer, self.mailserver, > self.mailserverport) > [ALERT] 110/232321 (682) : Lua task: runtime error: > /root/haproxytest/test.lua:267: connect: cannot use socket on other thread. > > Let me know if there is a patch or something else i can test/check. Or should > configure differently.?. > Thanks in advance. > > Regards, > > PiBa-NL (Pieter) > > #### haproxy.conf & lua scripts#### > Basically the serverhealth_smtpmail_haproxy.conf > <https://github.com/PiBa-NL/MyPublicProjects/blob/master/haproxy/lua-scripts/serverhealth_smtpmail_haproxy.conf> > and the files it links to are here: > https://github.com/PiBa-NL/MyPublicProjects/tree/master/haproxy/lua-scripts > > p.s. > The 'mailer' code if anyone is interested that was used is written in some > 'libraries' ive committed on github link, maybe they are of use to someone > else as well :) comments and fixes are welcome ;).. They are 'first versions' > but seem functional with limited testing sofar :). >

