【问题标题】:Lua entry thread aborted: runtime error: table overflowLua入口线程中止:运行时错误:表溢出
【发布时间】:2021-01-01 06:04:09
【问题描述】:

我是 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。谁能告诉我这里可能是什么问题?

【问题讨论】:

标签: nginx lua openresty


【解决方案1】:

我的立场是正确的。 ffi[[ 和 ffi([[ 都可以接受

【讨论】:

    猜你喜欢
    • 2023-01-24
    • 2015-07-18
    • 2016-07-26
    • 2018-12-16
    • 2010-10-21
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多