table overflow

567 views
Skip to first unread message

Tim Burgess

unread,
Oct 9, 2016, 7:57:33 AM10/9/16
to openresty-en
I've been receiving the following in some Openresty/Luajit code I have been running that uses the FFI:

2016/10/04 18:45:09 [error] 25391#0: *328 lua entry thread aborted: runtime error: table overflow

stack traceback:

coroutine 0:

        [C]: in function 'cdef'

        /home/ben/src/chickpea/serve_image.lua:89: in function </home/ben/src/chickpea/serve_image.lua:1>



I read somewhere that this is the C definitions being repeatedly loaded by each thread (i.e. each request) and thus leading to an internal table overflow.

My use of FFI is:


    local ffi = require "ffi"


and an example of one of my cdefs is:


    ffi.cdef [[

    typedef int pid_t;

    void *malloc(size_t sz);

    void *realloc(void*ptr, size_t size);

    void free(void *ptr);

    int sprintf(char *str, const char *format, ...);

    int printf(const char *format, ...);

    ..


Am I correct that this is a cdef-related overflow? And if so, what am I doing wrong. I do have a number of cdefs in different lua files. Should I consolidate them?


Thanks, Tim



Yichun Zhang (agentzh)

unread,
Oct 10, 2016, 3:59:23 PM10/10/16
to openresty-en
Hello!

On Sun, Oct 9, 2016 at 4:57 AM, Tim Burgess wrote:
> I've been receiving the following in some Openresty/Luajit code I have been
> running that uses the FFI:
>
> 2016/10/04 18:45:09 [error] 25391#0: *328 lua entry thread aborted: runtime
> error: table overflow
>

This is a common FFI usage mistake and also a FAQ. This is usually
because that you call the FFI API in the wrong way. It's wrong to call
ffi.cdef() repeatedly for the same things (like on every request
served by nginx). Always call it on the top-level scope of your own
Lua module files. See lua-resty-string and lua-resty-core for the
correct usage in the real world.

BTW, the next time you see an error, better google for it :) I believe
you can find my previous answers to this same question ;)

Regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages