too many results to resume

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

too many results to resume

Jeremy Jurksztowicz
Hello,

I'd like to have some info under what circumstances does the "too many
results to resume." error occur? I'm running a coroutine and upon it's
return this error pops up. I put a breakpoint at the error and noticed
that the nres (number of results) is 0, and lua_checkstack(L, nres+1)
fails. So I assumed that my stack was getting trashed somewhere (Is
that assumption wrong?). To find the source of the error I stackdumped
at the end of the function that is being run in the coroutine and got
only one stack element: The thread (coroutine) that is running the
function. I also stackdumped at the actual error (right before it
prints the message) and got a stack filled with A) My error function
that I pass to lua_pall B) Booleans (true and false) C) The number 1.
So somewhere between the return call and the end of coroutine.resume
something goes awfully wrong. My first instinct was to look for
infinite loop/recursion, but couldn't find one. So my questions are:

1) Under what conditions would a "too many results to resume." error
most likely occur.

2) When I dump the stack of the coroutine, the first (only) value on
the stack is the 'thread: 0xaddress' value of the coroutine. This
makes me suspect some sort of infinite recursion is going on, but I
don't know lua internals, so: is the coroutine supposed to be the
first element on it's own stack?

I'd like to give a better context for the code, but it's running in
quite a complex scaffolding, too large to put here.

Thanks for your time.

Reply | Threaded
Open this post in threaded view
|

Re: too many results to resume

Patrick Donnelly
On Thu, May 5, 2011 at 10:36 AM, Jeremy Jurksztowicz
<[hidden email]> wrote:

> Hello,
>
> I'd like to have some info under what circumstances does the "too many
> results to resume." error occur? I'm running a coroutine and upon it's
> return this error pops up. I put a breakpoint at the error and noticed
> that the nres (number of results) is 0, and lua_checkstack(L, nres+1)
> fails. So I assumed that my stack was getting trashed somewhere (Is
> that assumption wrong?). To find the source of the error I stackdumped
> at the end of the function that is being run in the coroutine and got
> only one stack element: The thread (coroutine) that is running the
> function. I also stackdumped at the actual error (right before it
> prints the message) and got a stack filled with A) My error function
> that I pass to lua_pall B) Booleans (true and false) C) The number 1.
> So somewhere between the return call and the end of coroutine.resume
> something goes awfully wrong. My first instinct was to look for
> infinite loop/recursion, but couldn't find one. So my questions are:
>
> 1) Under what conditions would a "too many results to resume." error
> most likely occur.

A (C) Lua stack cannot exceed LUAI_MAXCSTACK (8000). You passed too
many results to coroutine.resume:

> t = {}; for i = 1, 8000 do t[i] = 1 end
> coroutine.resume(coroutine.create(function() end), unpack(t))
stdin:1: too many results to unpack
stack traceback:
        [C]: in function 'unpack'
        stdin:1: in main chunk
        [C]: ?
> t = {}; for i = 1, 7999 do t[i] = 1 end
> coroutine.resume(coroutine.create(function() end), unpack(t))

--
- Patrick Donnelly

Reply | Threaded
Open this post in threaded view
|

Re: too many results to resume

Tony Finch
Patrick Donnelly <[hidden email]> wrote:
>
> A (C) Lua stack cannot exceed LUAI_MAXCSTACK (8000). You passed too
> many results to coroutine.resume:
>
> > t = {}; for i = 1, 8000 do t[i] = 1 end
> > coroutine.resume(coroutine.create(function() end), unpack(t))
> stdin:1: too many results to unpack

That isn't quite the right error message, but this is:

> t = {}; for i = 1, 7999 do t[i] = 1 end
> coroutine.resume(coroutine.create(function() return unpack(t) end))
stdin:1: too many results to resume
stack traceback:
        [C]: in function 'resume'
        stdin:1: in main chunk
        [C]: ?

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
Rockall, Malin, Hebrides: South 5 to 7, occasionally gale 8 at first in
Rockall and Malin, veering west or northwest 4 or 5, then backing southwest 5
or 6 later. Rough or very rough. Occasional rain. Moderate or good,
occasionally poor.

Reply | Threaded
Open this post in threaded view
|

Re: too many results to resume

Patrick Donnelly
On Thu, May 5, 2011 at 11:06 AM, Tony Finch <[hidden email]> wrote:

> Patrick Donnelly <[hidden email]> wrote:
>>
>> A (C) Lua stack cannot exceed LUAI_MAXCSTACK (8000). You passed too
>> many results to coroutine.resume:
>>
>> > t = {}; for i = 1, 8000 do t[i] = 1 end
>> > coroutine.resume(coroutine.create(function() end), unpack(t))
>> stdin:1: too many results to unpack
>
> That isn't quite the right error message, but this is:
>
>> t = {}; for i = 1, 7999 do t[i] = 1 end
>> coroutine.resume(coroutine.create(function() return unpack(t) end))
> stdin:1: too many results to resume
> stack traceback:
>        [C]: in function 'resume'
>        stdin:1: in main chunk
>        [C]: ?

Oops, thanks :).

--
- Patrick Donnelly

Reply | Threaded
Open this post in threaded view
|

RE: too many results to resume

Jeremy Jurksztowicz
In reply to this post by Jeremy Jurksztowicz
Sorry, I should have mentioned that I return NO results from the
coroutine. The return statement is empty. At every crash, the number
of results is zero, and the lua_checkstack(L, nres+1) call returns
false. So there are not too many results, there just isn't room for 1
more element on the stack. Here is how the code roughly looks.
Everything below is run in a lua_pcall with an error handler.

function run ()
    print("running coroutine...")
    -- ... some things happen here
    dump_stack(action.co) -- coroutine stack has 1 element: thread: 0xaddress
    dump_stack() -- main stack has no elements
    return result -- return value is always either nil, or a short string
end

action.co = coroutine.create(run)

print("preparing to run coroutine...")
dump_stack() -- main stack is empty
local ret = {coroutine.resume(action.co)}
print("coroutine finished.") -- never gets here, instead my error
handler is called with the "too many results to resume." error, and
the stack is filled up with thousands of copies of my error handler,
booleans and the number 1.

Hope someone can see something that I missed, this bug has been a
total nightmare for a week!

Thanks!