Skip to content

Commit

Permalink
stats: fix LuaJit breaking pairs __gc
Browse files Browse the repository at this point in the history
In some cases LuaJit optimizes using gc_observer table to handle pairs
object gc. It had lead to incorrect behavior (ignoring some pairs
interrupted with break in stats) and tests fail in some cases
(for example, if you run only stats unit tests).

Part of #224
  • Loading branch information
DifferentialOrange committed Feb 25, 2022
1 parent 7ee2d7d commit aeb21e6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crud/stats/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ local function setmt__gc(t, mt)
return setmetatable(t, mt)
end

-- If jit will be enabled here, gc_observer usage
-- may be optimized so our __gc hack will not work.
local function keep_observer_alive(gc_observer) --luacheck: ignore
end
jit.off(keep_observer_alive)

local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
local total_latency = build_latency

Expand All @@ -139,7 +145,7 @@ local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
local wrapped_gen = function(param, state)
-- Mess with gc_observer so its lifespan will
-- be the same as wrapped_gen() function.
gc_observer[1] = state
keep_observer_alive(gc_observer)

local start_time = clock.monotonic()

Expand Down

0 comments on commit aeb21e6

Please sign in to comment.