当我使用以下脚本时:
local smtp = require("socket.smtp")
local from = "from@host"
local rcpt = "rcpt@host"
local msg = {
headers = {
to = rcpt,
subject = "Hi"
},
body = "Hello"
}
smtp.send{from = from,rcpt = rcpt,source = smtp.message(msg)}
我收到一条错误消息:
lua entry thread aborted: runtime error: attempt to yield across C-call boundary
.我正在使用最新的
luasocket
安装自 luarocks
使用 LuaJIT 2.1 编译的使用 nginx 的 Lua 5.1。是什么导致了此错误消息,我该如何解决?
最佳答案
这是由 LuaJIT 和 socket.smtp 的组合使用引起的,它启动了一个协程。来自 https://github.com/openresty/lua-nginx-module/issues/376 :
@AterCattus This is a known limitation in LuaJIT (and the standard Lua 5.1 interpreter) that the require() builtin is currently implemented as a C builtin across which you cannot initiate a yield.
看起来最好的解决方法可能是使用 require.lua 的这个实现:https://github.com/pygy/require.lua .它是用纯 Lua 而不是 C 编写的,以解决 LuaJIT 的这个问题。
关于nginx - Luasocket + nginx 错误 - lua 入口线程中止 : runtime error: attempt to yield across C-call boundary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30111808/