[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C stack overflow with coroutine.close
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 19 Oct 2022 11:50:32 -0300
> 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.
Many thanks for the feedback.
-- Roberto