Skip to content

Commit 5ea178b

Browse files
stats: fix LuaJit breaking pairs __gc
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
1 parent db79bfb commit 5ea178b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crud/stats/init.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ local function setmt__gc(t, mt)
118118
return setmetatable(t, mt)
119119
end
120120

121+
-- If jit will be enabled here, gc_observer usage
122+
-- may be optimized so our __gc hack will not work.
123+
local function keep_observer_alive(gc_observer) --luacheck: ignore
124+
end
125+
jit.off(keep_observer_alive)
126+
121127
local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
122128
local total_latency = build_latency
123129

@@ -140,7 +146,7 @@ local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
140146
local wrapped_gen = function(param, state)
141147
-- Mess with gc_observer so its lifespan will
142148
-- be the same as wrapped_gen() function.
143-
gc_observer[1] = state
149+
keep_observer_alive(gc_observer)
144150

145151
local start_time = clock.monotonic()
146152

0 commit comments

Comments
 (0)