# HG changeset patch # User daurnimator # Date 1420592519 18000 # Node ID 605a87e90e274c75c963069cbedf26f2887d19f0 # Parent 0f940a7ba489ed412514c922e61c64e6f8fb1e2d net.cqueues: Add workaround for luaevent callback getting collected diff -r 0f940a7ba489 -r 605a87e90e27 net/cqueues.lua --- a/net/cqueues.lua Tue Jan 06 19:33:25 2015 +0000 +++ b/net/cqueues.lua Tue Jan 06 20:01:59 2015 -0500 @@ -43,7 +43,11 @@ cq = cqueues.new(); -- Only need to listen for readable; cqueues handles everything under the hood local EV_READ = server.event.EV_READ; - server.base:addevent(cq:pollfd(), EV_READ, function(e) + local event_handle; + event_handle = server.base:addevent(cq:pollfd(), EV_READ, function(e) + -- Need to reference event_handle or this callback will get collected + -- This creates a circular reference that can only be broken if event_handle is manually :close()'d + local _ = event_handle; assert(cq:loop(0)); -- Convert a cq timeout to an acceptable timeout for luaevent local t = cq:timeout();