Hello!
On Fri, Jan 29, 2016 at 6:12 AM, Hadals Yang wrote:
> 直接访问index.lua ,index.lua require post.lua 然后在 post.lua 里面连库:
> local mysql = require ("resty.mysql")
> local db, err = mysql:new()
> local ok, err, errno, sqlstate =
> db:connect{host="127.0.0.1",port=3306,database="apitest",user="test",password="123456"}
>
> 出问题:
> lua entry thread aborted: runtime error: attempt to yield across C-call
> boundary
> stack traceback:
> coroutine 0:
> [C]: in function 'require'
永远不要在你自己的 Lua 模块顶层创建 cosocket 对象。顶层代码是由 require() 函数运行的,而 require()
函数不能 yield,同时还有一个问题是模块顶层的数据通常会跨越请求的边界,这是 cosocket 对象的生命期所不允许的。应该把
cosocket 操作封装在你自己的模块的*函数*里面,然后在请求处理程序里面调用。同时创建的 cosocket
对象永远不要超出请求的边界。更多细节请参考
https://github.com/openresty/lua-resty-mysql/#limitations
https://github.com/openresty/lua-nginx-module#data-sharing-within-an-nginx-worker
Regards,
-agentzh