From aeb21e6344b063990522eea9d134a4282a33cbf6 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Fri, 18 Feb 2022 10:24:57 +0300 Subject: [PATCH] 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 --- crud/stats/init.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crud/stats/init.lua b/crud/stats/init.lua index c2555791..1e1a8f83 100644 --- a/crud/stats/init.lua +++ b/crud/stats/init.lua @@ -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 @@ -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()