From 144deef96dae9850428aac8c41fd05a51bbee2eb 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 6a7cccfe4..b224c5ff8 100644 --- a/crud/stats/init.lua +++ b/crud/stats/init.lua @@ -118,6 +118,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 @@ -142,7 +148,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()