nginx - Luasocket + nginx 错误 - lua 入口线程中止 : runtime error: attempt to yield across C-call boundary

标签 nginx lua luajit luasocket luarocks

当我使用以下脚本时:

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/

相关文章:

node.js - 通过nodejs、njs脚本语言扩展nginx

java - 如何使用 Nginx 和 dropwizard 部署 angularjs 应用程序前端

nginx - 如何在 Lua 中对 request_uri 字符串进行 urldecode

performance - Lua字符串转数字解析速度优化

lua - 使用 Linux 制作命令行命令

lua - 访问 torch 神经网络的内部神经元

c - Lua (LuaJit) 和 C 中的对象生命周期

image - 是否存在任何开源独立的 Restful 图像服务器?

c++ - 从 Lua 修改 main() 中的 C++ 数组,无需额外分配

javascript - 404 在 nuxt.js 上找不到 sitemap.xml