[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: C stack overflow with coroutine.close
- From: Xmilia Hermit <xmilia.hermit@...>
- Date: Thu, 13 Oct 2022 20:48:52 +0200
I found that coroutine.close does not update the nCcalls variable of the
coroutine it switches to when running the __close methods. This can lead
to loss of the C call count and a stack overflow as the following code
demonstrates:
local coro = {}
local n = 1
for i = 1, 100000 do
coro[i] = coroutine.create(function()
local cc <close> = setmetatable({}, {__close=function()
n = n + 1
coroutine.close(coro[n])
end})
coroutine.yield()
end)
coroutine.resume(coro[i])
end
coroutine.close(coro[1])
This creates 100000 coroutines with low nCcalls counts and then closes
all through the __close method using lots of C stack.
Regards,
Xmilia