Nginx/Lua 行为异常

我是 Lua 新手,正在试图从 Lua 调用一个共享对象(go 代码),它基本上是身份验证代码,如果验证成功,则路由到上游,否则抛出 forbidden,然而,我看到奇怪的行为,每当我在 Nginx 重新加载后进行 CURL 时,身份验证成功,并且 Nginx 路由到上游,但是每个随后的 CURL 都会导致以下错误。

020/08/14 15:12:53 [error] 187#187: *18 lua entry thread aborted: runtime error:
/usr/local/openresty/nginx/auth.lua:18: cannot change a protected metatable
stack traceback:
coroutine 0:

Auth.lua 文件

-- auth.lua
local ffi = require("ffi")

local im = ffi.load("/lib.so")

ffi.cdef([[
 typedef long long GoInt64;
 typedef unsigned long long GoUint64;
 typedef GoInt64 GoInt;
 typedef struct { const char *p; GoInt n; } GoString;
 extern GoInt VerifyToken(GoString p0);

]]);

local accessToken = string.sub(ngx.var.http_Authorization,8)
local typeString = ffi.metatype("GoString", {})
--- 上面一行抛出错误 ^^^^
local  accessTokenString= typeString(accessToken, string.len(accessToken))

local result = im.VerifyToken(accessTokenString)

if tonumber(result)==1LL then
 -- 我们已经 oK 了,继续路由到上游
else
 ngx.exit(ngx.HTTP_FORBIDDEN)
end

有人能告诉我问题是什么吗?

点赞