lua-debug icon indicating copy to clipboard operation
lua-debug copied to clipboard

Assertion Errors pauses execution even when disabled

Open thewhitegoatcb opened this issue 2 years ago • 9 comments

Asserts caused when they are disabled causes to pause execution without poping any errors or showing a paused state image State shows as running: image Enabling them in that state immediately shows the assert error that caused the pause and enables to continue execution manually

thewhitegoatcb avatar Jun 12 '23 06:06 thewhitegoatcb

@fesily

actboy168 avatar Jun 12 '23 09:06 actboy168

Cannot be reproduced, provide minimum reproduction example.

fesily avatar Jun 12 '23 10:06 fesily

Sorry for the delay, I cannot reproduce on a minimal setup. It's intermittent so a bit hard to track.

thewhitegoatcb avatar Jun 16 '23 08:06 thewhitegoatcb

Checked it today, apparently local function traceback(flags, error) was profiled at 500-700ms for each exception. A way to reproduce would be to run a lot of asserts in a a protected loop with at least one of the exception filters enabled that isn't related to the assert. My temp fix is adding


function m.hasExceptionFilters(flags)
    for _, flag in ipairs(flags) do
        if exceptionFilters[flag] ~= nil then
            return true
        end
    end
    return false
end

....

local function runException(flags, errobj)
    if not breakpoint.hasExceptionFilters(flags) then 
        return 
    end

....

thewhitegoatcb avatar Jun 19 '23 17:06 thewhitegoatcb

Do you mean that the traceback is too slow to cause this problem. I still can't reproduce what you said

while true do
  pcall(function ()
    while true do
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(true)
      assert(false)
    end
  end)
end

fesily avatar Jun 21 '23 08:06 fesily

Narrowed it down to local function findfield(t, f, level) being expensive to run on big environments with a lot of globals, we should find a way to cache the name or location of the function. Imo it isn't a big issue but currently this will happen if any exception catching is enabled even if it's not the one that is related to the assert. So my quick fix I proposed earlier might be good enough for now. Here's a test case, this runs at about 100ms per loop on my machine

local function create_big_env(num_tables, table_size)
    for i=1, num_tables do
        local T = {}
        for j=1, table_size do
            T["k"..j] = 123
        end
        rawset(_G, "T"..i, T)
    end
end

local function test()
    while true do
        local start = os.clock()
        pcall(function ()
            assert(false)
        end)
        print(os.clock() - start)
    end
end

create_big_env(100, 1000)
test()

thewhitegoatcb avatar Jun 22 '23 12:06 thewhitegoatcb

So the initial problem was caused by the slow running of the filter exception function, I can assume so?

fesily avatar Jun 25 '23 02:06 fesily

Yes, it's not a luajit specific issue it seems

thewhitegoatcb avatar Jun 25 '23 05:06 thewhitegoatcb

You can submit a pull

fesily avatar Jun 25 '23 06:06 fesily