lua-users home
lua-l archive

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


I wrote a small module 
https://github.com/cloudwu/lua-snapshot 

It can record all the GCobjects into another states. We can do some snapshots after an interval of time and compares the diff to find possible leaks.

Sean Conner <sean@conman.org>于2019年5月16日 周四05:45写道:

  Okay, I realize Lua has GC, so it's not a leak per se, but I am somehow
keeping references to data somewhere, and I can't seem to track them down.
The last time I encountered this issue, I was able to study the code and
through deductive reasoning, found the issue [1].

  But this time, not so much.  In general, how do others track down "lost"
references?  I just can't seem to locate it this time.

  In specific, the code (which I can't post sadly, because it's at work)
uses Lua 5.1 and is very simple.  It uses my network driver [2] which is
used in another project [3] which doesn't have the issue.  The major
difference between the two is that the "leaky" code uses TCP [4] in addition
to UDP.

  The program just accepts a packet via UDP (no response required---it's a
"fire-and-forget" type situation).  It then unpacks the data (which comes in
as CBOR), re-codes it as JSON, then then POSTs the data to an HTTP endpoint
elsewhere on the local network.  And *that's it!* That's what makes this so
maddening---it's so simple there's not obvious place for references to
accumulate, or at least, none that I can see, which is why I'm asking for
advice.

  -spc (Off to stare at code ... )

[1]     "Oh, if the coroutine crashes *here,* I still have a strong
        *reference to it there* ... "

[2]     https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl.lua

        It's an event loop that waits for activity from a set of file
        descriptors (usually network connections) and when packets come in,
        runs a function specific to the file descriptor which can schedule a
        coroutine to run to handle any processing.

[3]     Mainly, code that processes something like 60,000,000 SIP messages
        per day, but they're all delivered via UDP.

[4]     https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl/tcp.lua

        which uses

        https://github.com/spc476/lua-conmanorg/blob/master/lua/net/ios.lua

        to mimic the Lua file:read() API.

--
http://blog.codingnow.com