JakobGreen / lua-requests

Requests for Lua!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is lua-requests thread-safe?

tobiasschweizer opened this issue · comments

We are developing a software in C++ that makes use of Lua to easily implement some custom functionalities the user may wish to have. The software implements an API to request images in a specified resolution, rotation etc.

In https://github.com/dhlab-basel/Sipi/blob/develop/sipi.init-knora.lua, we implemented a Lua function that is called each time a client makes a request to our API. Each request is handled in a separate thread.

function pre_flight(prefix,identifier,cookie)

    -- use Sipi's luarocks to install these modules
    requests = require "requests"
    json = require "json"
...

We encountered a Lua problem when a lot of requests were made to our API at the same time. The application crashed. However, when we commented out requests = require "requests", all went fine again.

So could it be a problem that requests is loaded by separate threads at the same time? Each thread has its own Lua interpreter.

I don't know exactly what would be wrong, but I am going to guess that it is most likely an issue with the dependency luasocket. I don't think there is any other reason why requests wouldn't be thread safe. Without any further investigation I wouldn't know for sure though.

In fact also we had a look at luasocket because we had the same suspicion. I will ask them and get back to you when I know more.

Thx.

Looks like luasocket is not thread-safe.