Skip to content

Commit aeb21e6

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 7ee2d7d commit aeb21e6

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
@@ -117,6 +117,12 @@ local function setmt__gc(t, mt)
117117
return setmetatable(t, mt)
118118
end
119119

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

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

144150
local start_time = clock.monotonic()
145151

0 commit comments

Comments
 (0)