Dear list,
I'm using the lua-resty-mysql driver in an OpenResty application, and I keep on receiving the error:
, client: 127.0.0.1, server: , request: "POST /users? HTTP/1.1", host: "127.0.0.1"
2013/11/10 13:09:44 [error] 39782#0: *1 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
[C]: in function 'require'
[string "content_by_lua"]:1: in function <[string "content_by_lua"]:1>, client: 127.0.0.1, server: , request: "POST /users? HTTP/1.1", host: "127.0.0.1"
According to the library limitations [1], I should not use it in init_by_lua and similar functions (which I'm not), and the resty.mysql instance is not stored at a module level. This is the connect portion:
local function mysql_connect(options)
-- ini mysql
local mysql = require "resty.mysql"
-- create sql object
local db, err = mysql:new()
if not db then error("failed to instantiate mysql: " .. err) end
-- set 1 second timeout for suqsequent operations
db:set_timeout(timeout_subsequent_ops)
-- connect to db
local db_options = {
host = options.host,
port = options.port,
database = options.database,
user = options.user,
password = options.password,
max_packet_size = max_packet_size
}
local ok, err, errno, sqlstate = db:connect(db_options)
if not ok then error("failed to connect to mysql: " .. err .. ": " .. errno .. " " .. sqlstate) end
-- return
return db
end
I do, however, store the module that calls the mysql_connection here above at global level.
Any ideas?
Thanks,
r.
[1] https://github.com/agentzh/lua-resty-mysql#limitations