kernelsauce / turbo

Turbo is a framework built for LuaJIT 2 to simplify the task of building fast and scalable network applications. It uses a event-driven, non-blocking, no thread design to deliver excellent performance and minimal footprint to high-load applications while also providing excellent support for embedded uses.
http://turbo.readthedocs.io/
Apache License 2.0
527 stars 84 forks source link

Error in IOLoop handler. attempt to index global 'bit' #316

Closed source-data closed 7 years ago

source-data commented 7 years ago

I am trying to use Turbo (installed via luarocks) on an Amazon EC2 Linux AMI to make a simple REST API and use it for a web application that makes AJAX requests (in response to key strokes). If the requests are too fast, I get the following error:

[E 2017/07/06 15:12:09] [ioloop.lua] Error in IOLoop handler.
▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
/usr/local/share/lua/5.1/turbo/socket_ffi.lua:339: attempt to index global 'bit' (a number value)
stack traceback:
    /usr/local/share/lua/5.1/turbo/socket_ffi.lua:339: in function 'set_nonblock_flag'
    /usr/local/share/lua/5.1/turbo/iostream.lua:114: in function 'initialize'
    ...share/lua/5.1/turbo/3rdparty/middleclass/middleclass.lua:90: in function 'IOStream'
    /usr/local/share/lua/5.1/turbo/tcpserver.lua:209: in function </usr/local/share/lua/5.1/turbo/tcpserver.lua:200>
    /usr/local/share/lua/5.1/turbo/sockutil.lua:244: in function </usr/local/share/lua/5.1/turbo/sockutil.lua:204>
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/turbo/ioloop.lua:546: in function '_run_handler'
    /usr/local/share/lua/5.1/turbo/ioloop.lua:454: in function '_event_poll'
    /usr/local/share/lua/5.1/turbo/ioloop.lua:443: in function 'start'
    smtagapi.lua:158: in function 'start'
    smtagapi.lua:52: in function 'launch'
    smtagapi.lua:165: in main chunk
    [C]: in function 'dofile'
    ...user/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
    [C]: at 0x004064c0
▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲

It works fine on MacOSX but not on the Amazon LINUX instance. Apologies if I am doing nonsense...

Here is the code:

local turbo = require 'turbo'

local smtagapi = {}

function smtagapi.complete(input_string, format)
...
end

function smtagapi.REST(port)
    local port = port or 7475
    local DefaultHandler = class("DefaultHandler", turbo.web.RequestHandler)
    local HelloWorld = class("HelloWorld", turbo.web.RequestHandler)

    function DefaultHandler:post()
         self:add_header("Access-Control-Allow-Origin", "*")
         local input_string = self:get_argument("text", "")
         local format = self:get_argument("format", "html")
         local response = smtagapi.complete(input_string, format)
         self:write(response)
    end

    function HelloWorld:get()
        local text = self:get_argument("text", "")
        if text ~="" then 
            self:write("Something was sent via ?text= : <br/>")
            self:write(text) 
        end
        self:write("<p>It works :-)</p>")
    end

    smtagapi_app = turbo.web.Application({
             {"/smtagapi", DefaultHandler},
             {"/hello", HelloWorld}
    })

    smtagapi_app:listen(port)
end

function smtagapi.start()
    turbo.ioloop.instance():start()
end

function smtagapi.launch()
    smtagapi.load_models()
    smtagapi.REST(7475)
    smtagapi.start()
end

if not package.loaded['smtagapi'] then
    print('launching smtagapi server')
    smtagapi.launch()
end

return smtagapi
kernelsauce commented 7 years ago

Should be fixed in master now. :)