lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

I've been (ab)using the registry in a traffic application at work,
employing it as a simple database to store key/value pairs.  Every
message the application sends, whether acknowledgement or command, is
stored in the registry for some few (milli)seconds and then removed. 
Commands are stored until the app receives an ack from its peer; the
app keeps its own acks around for resending in case its peer sends a
duplicate command.  Here's all the code that uses the registry:

static void put_libevent(const char* key, const LibEvent* le)
{
    lua_pushstring(LS, key);
    lua_pushlightuserdata(LS, (void*)le);
    lua_rawset(LS, LUA_REGISTRYINDEX);
}

static LibEvent* get_libevent(const char* key)
{
    lua_pushstring(LS, key);
    lua_rawget(LS, LUA_REGISTRYINDEX);
    LibEvent* le = (LibEvent*)lua_touserdata(LS, -1);
    lua_pop(LS, 1);
    return le;
}

static void zap_libevent(const char* key)
{
    lua_pushstring(LS, key);
    lua_pushnil(LS);
    lua_rawset(LS, LUA_REGISTRYINDEX);
}

Of course LS is the stack.  This has been working very well for weeks
but this morning I found a core dump on one of the traffic boxes. 
Here's the top of the gdb backtrace:

Core was generated by `./gcpish.8 OTT2/cfg_gwc5_abcdefg'.
Program terminated with signal 11, Segmentation fault.
#0  0x08112c0e in newkey ()
(gdb) bt
#0  0x08112c0e in newkey ()
#1  0x0810bd4c in lua_rawset ()
#2  0x080d0d81 in put_libevent (key=0xfef7cf70 "10.65.32.56  24882", 
    le=0xd7c4ec4) at resend.cpp:10
etc. ...

As I just discovered, lua_rawset doesn't call newkey directly.  Before
figuring that out, I thought I'd ask what might have gone wrong.  Did
my traffic box run out of memory?  Does my use of the registry look
suspicious?  The app doesn't use threads.  I can provide more
information if need be, but I think this message is already too long.

Thanks,
Steve