Hi Robert,

I add Thierry to the discussion (see below for the details).

Le 19/02/2016 20:15, Robert Samuel Newson a écrit :
Hi,

I think I've found a bug in core.msleep (and core.sleep);

foo.lua;

core.register_service("foo", "http", function(applet)
   core.msleep(1)
   local body = "hello"
   applet:set_status(200)
   applet:add_header("Content-Length", string.len(body))
   applet:start_response()
   applet:send(body)
end)

haproxy.cfg

global
   lua-load foo.lua

defaults
   mode http
   timeout client 150000
   timeout server 3600000
   timeout connect 5000
   timeout queue 5000

listen l
   bind 127.0.0.1:6000
   http-request use-service lua.foo

--

steps to reproduce;

curl 127.0.0.1:6000

this will not respond at all.

If you comment out the core.msleep(1) line, you get the expected 200 response.

This seems to occurs wherever core.msleep is used but I've only confirmed this 
behaviour in register_service and register_action functions.

I'm not expert in the lua code area, but after some tests, I wonder if the calls to hlua_yieldk() shoudln't provide the HLUA_CTRLYIELD flag in this functions :
- hlua_sleep_yield
- hlua_sleep
- hlua_msleep

Giving something like :
diff --git a/src/hlua.c b/src/hlua.c
index 5cf2320..022c107 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -4983,7 +4983,7 @@ __LJMP static int hlua_sleep_yield(lua_State *L, int status, lua_KContext ctx)
 {
        int wakeup_ms = lua_tointeger(L, -1);
        if (now_ms < wakeup_ms)
-               WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, HLUA_CTRLYIELD));
        return 0;
 }

@@ -4998,7 +4998,7 @@ __LJMP static int hlua_sleep(lua_State *L)
        wakeup_ms = tick_add(now_ms, delay);
        lua_pushinteger(L, wakeup_ms);

-       WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, HLUA_CTRLYIELD));
        return 0;
 }

@@ -5013,7 +5013,7 @@ __LJMP static int hlua_msleep(lua_State *L)
        wakeup_ms = tick_add(now_ms, delay);
        lua_pushinteger(L, wakeup_ms);

-       WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_sleep_yield, wakeup_ms, HLUA_CTRLYIELD));
        return 0;
 }

Also, I'm not sure about the wake_time type in "struct lua" : shouldn't it be declared as an unsigned int ? Which then implies some type changes in other parts of the code, for example :
- in hlua_sleep_yield() : unsigned int wakeup_ms
- or in hlua_yieldk() : shouldn't "int timeout" be declared as an unsigned int also ?

Sorry, I can't have a more longer look on this tonight.

--
Cyril Bonté

Reply via email to