Table overflow problem in openresty by ffi calling C function

33 views
Skip to first unread message

lan hust

unread,
Apr 26, 2025, 4:37:07 AMApr 26
to open...@googlegroups.com
Dear all and Yichun Zhang (agentzh),
      I have read the discussion about Calling C function in openresty by ffi module, and report table overflow in https://groups.google.com/g/openresty-en/c/I5Vax1jDIsM.

and with your suggestions, i fix my lua code by writing new lua module , but it still report table overflow, i don't understand why, please help me ,thank a lot.

below is my lua code:
openresty lua:

nginx.conf:

...
location ~ ^/(cdnlog|livertmp) {
default_type 'text/html';
access_by_lua_file conf/lua/cdnlog.lua;
proxy_pass http://$http_host$request_uri;
}
...

cdnlog.lua:
...
attr= require("attr_api")

function check_request_k(key)
attr.attr_api(12345, 1)
end

check_request_k(ngx.req.get_uri_args()['k'])
...


attr_api.lua
local ffi = require "ffi"

local _M = { _VERSION = "0.1" }

ffi.cdef[[
    int Attr_API(int attr, int iValue);            
]]

local myffi = ffi.load("/usr/servers/nginx/conf/lua/libAttr_API.so")

function _M.attr_api(id, value)
    if not myffi or not myffi.Attr_API then
        ngx.log(ngx.ERR, "Load attr_api failed: ", err)
        return
    end
    local ok, err = pcall(myffi.Attr_API, id, value)
    if not ok then
        ngx.log(ngx.ERR, "Attr_API call failed: ", err)
    end
end

return _M

this lib (/usr/servers/nginx/conf/lua/libAttr_API.so) is not problem, the Attr_API function work correctly.

but after running one day, it report:
2025/04/26 06:43:53 [error] 34231#0: *439920047 lua entry thread aborted: runtime error: table overflow
stack traceback:
coroutine 0:
        [C]: in function 'cdef'

Junlong li

unread,
Apr 26, 2025, 5:47:46 AMApr 26
to openresty
you can give a minimal example that can reproduce this issue.

lan hust

unread,
May 1, 2025, 9:32:27 PMMay 1
to open...@googlegroups.com
i make a simple test for more times ,it dosn't appear and works correctly , surprising

file  main.lua:
local attr= require("attr_api")
local times=1000000000
local a = 0
while a < times do
    attr.attr_api(33712153 , 1)
    a = a+1
end
print("finish:", a)



file attr_api.lua:


local ffi = require "ffi"

local _M = { _VERSION = "0.1" }

ffi.cdef[[
    int Attr_API(int attr, int iValue);            
]]

local myffi = ffi.load("/usr/servers/nginx/conf/lua/libAttr_API.so", global)


function _M.attr_api(id, value)
    if not myffi or not myffi.Attr_API then
        print("Load attr_api failed: ")

        return
    end
    local ok, err = pcall(myffi.Attr_API, id, value)
    if not ok then
        print("Attr_API call failed: ", err)
    end
end

return _M

lan hust <hustl...@gmail.com> 于2025年4月26日周六 16:36写道:


Junlong li <zhuizhu...@gmail.com> 于2025年4月26日周六 17:47写道:
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
---
您收到此邮件是因为您订阅了Google群组上的“openresty”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到openresty+...@googlegroups.com
如需查看此讨论,请访问 https://groups.google.com/d/msgid/openresty/cf98e43e-095a-4638-bf44-d8dbfb5f88c0n%40googlegroups.com
Reply all
Reply to author
Forward
0 new messages