如何解决Lua入口线程异常终止:运行时错误:表溢出
我是Lua和Nginx的新手。我有一个Lua文件,该文件对命中NGINX的任何请求进行身份验证。
local ffi = require("ffi")
local cjson = require("cjson")
local iam = ffi.load("/gateway/auth/main/libiam.so")
ffi.cdef([[
typedef long long GoInt64;
typedef GoInt64 GoInt;
typedef struct { const char *p; GoInt n; } GoString;
extern GoInt VerifyToken(GoString p0);
extern GoInt64 VerifyApiKey(GoString p0);
]]);
local accessToken = ""
local apiKey = ""
local result = 0
local typeString = ffi.typeof("GoString")
local unauthorizedJson={}
if ngx.var.http_Authorization and string.len(ngx.var.http_Authorization) > 0 then
if ngx.var.http_Authorization:sub(1,#"Bearer") == "Bearer" then
ngx.log(ngx.STDERR,'Verifying bearer token.')
accessToken = string.sub(ngx.var.http_Authorization,8)
local accessTokenString= typeString(accessToken,string.len(accessToken))
result = iam.VerifyToken(accessTokenString)
else
apiKey = ngx.var.http_Authorization
local apiKeyString= typeString(apiKey,string.len(apiKey))
result = iam.VerifyApiKey(apiKeyString)
end
if tonumber(result)~=0 then
-- we are ok here and proceed to route to upstream
if string.len(apiKey) > 0 then
ngx.req.set_header("abc",result)
end
else
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
else
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
我间歇性地看到以下错误
Lua entry thread aborted: runtime error: table overflow
在此行
ffi.cdef([[
我正在使用openresty。谁能告诉我这里的问题是什么?
解决方法
我站得住脚了。 ffi [[和ffi([[都可以接受
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。