Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to unpersist an in-progress coroutine seg faults #6

Closed
hoelzro opened this issue Jun 10, 2011 · 28 comments
Closed

Attempting to unpersist an in-progress coroutine seg faults #6

hoelzro opened this issue Jun 10, 2011 · 28 comments

Comments

@hoelzro
Copy link
Owner

hoelzro commented Jun 10, 2011

Title says it all. Test script:

local pluto = require 'pluto'

local coro = coroutine.create(function()
  for i = 1, 10 do
    coroutine.yield(i * i)
  end
end)

for i = 1, 5 do
  print(coroutine.resume(coro))
end
local perms = {
  [coroutine.yield] = coroutine.yield
}
local s = pluto.persist(perms, coro)
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
  print(coroutine.resume(coro))
end
@lilith
Copy link

lilith commented Sep 5, 2011

I'm now using 5.1.3 on OS X.

I'm having trouble persisting a suspended coroutine.

I persist this:

code = {
["name"] = "world.start.start";
["co"] = "thread: 0x100114510";
};

and get back this:
code = {
["\000\000\000\000"] = 3.6073928448386e-313;
};

Persistence of suspended co-routines was my primary motivation for working with Lua. Is there a workaround?

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 5, 2011

I think in order for this to work, this bug will need to be fixed. I'm not actively using Pluto anymore, so my maintainership of the project hasn't been the most active, but I'll see if I can fit in an hour or two today to look at it.

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 5, 2011

@nathanaeljones In response to your "should I move to Rhino?" question, you may not have to. I took a look at your Weaver project; maybe I'm not understanding it entirely, but why are you persisting coroutines to disk between resumes? Why not just store them in memory, like Copas does?

@lilith
Copy link

lilith commented Sep 5, 2011

Well, my prototype currently uses the console, but is intended for a web-based game. State needs to persist between user sessions, which could be anywhere between a day and a year. Volatile memory wouldn't work very well.

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 5, 2011

Ok, makes sense. Do you really need to model a user's experience as a single call to start_game()?

@lilith
Copy link

lilith commented Sep 5, 2011

I'm not exactly sure what you mean....

I'm avoiding continuations as much as possible - I use a continuation-passing style to allow frequent hot code upgrades (being collaboratively-edited and all), but inside each 'file', there is a logic flow that would be hard to express if every branch required a separate function.

I'm trying to abstract the whole async and state thing away so that I can simplify game development enough to make a 'wiki game' work.

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 5, 2011

Could we move this discussion to e-mail? It's gotten highly specific to your game, and I'd like to keep this thread more general for others with this issue. Could you give a thorough explanation of how your web game will work so I can recommend alternatives if possible? My e-mail is rob@hoelz.ro.

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 5, 2011

Ok, I did some more testing, and it turns out this feature works fine; my example is just broken. If you try this:

local pluto = require 'pluto'

local coro = coroutine.create(function()
  for i = 1, 10 do
    coroutine.yield(i * i)
  end
end)

for i = 1, 5 do
  print(coroutine.resume(coro))
end
local perms = {
  [coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
  print(coroutine.resume(coro))
end

...it works fine.

@hoelzro hoelzro closed this as completed Sep 5, 2011
@lilith
Copy link

lilith commented Sep 5, 2011

What platform are you running? Versions?

Sent from my iPad

On Sep 5, 2011, at 10:37 PM, hoelzroreply@reply.github.com wrote:

Ok, I did some more testing, and it turns out this feature works fine; my example is just broken. If you try this:

local pluto = require 'pluto'

local coro = coroutine.create(function()
 for i = 1, 10 do
   coroutine.yield(i * i)
 end
end)

for i = 1, 5 do
 print(coroutine.resume(coro))
end
local perms = {
 [coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
 print(coroutine.resume(coro))
end

...it works fine.

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 5, 2011

Lua 5.1.4, OS X 10.6

nathanaeljones reply@reply.github.com wrote:

What platform are you running? Versions?

Sent from my iPad

On Sep 5, 2011, at 10:37 PM, hoelzroreply@reply.github.com wrote:

Ok, I did some more testing, and it turns out this feature works fine; my example is just broken. If you try this:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

...it works fine.

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

@lilith
Copy link

lilith commented Sep 5, 2011

On Lua 5.1.3 using the latest from the 'master' branch of your repo, I get

true 1
true 4
true 9
true 16
true 25
Segmentation fault

I'm using the code you sent me:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

What was the change you made to the example?

On Mon, Sep 5, 2011 at 11:30 PM, hoelzro <
reply@reply.github.com>wrote:

Lua 5.1.4, OS X 10.6

nathanaeljones reply@reply.github.com wrote:

What platform are you running? Versions?

Sent from my iPad

On Sep 5, 2011, at 10:37 PM, hoelzroreply@reply.github.com wrote:

Ok, I did some more testing, and it turns out this feature works fine; my
example is just broken. If you try this:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

...it works fine.

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The change is this:

perms = { [1] = coroutine.yield }

Have you tried this on Lua 5.1.4? Also, make sure you're using the same version of Lua that you compiled Pluto against; it's very sensitive to binary changes.

  • -Rob

On Sep 5, 2011, at 5:56 PM, nathanaeljones wrote:

On Lua 5.1.3 using the latest from the 'master' branch of your repo, I get

true 1
true 4
true 9
true 16
true 25
Segmentation fault

I'm using the code you sent me:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

What was the change you made to the example?

On Mon, Sep 5, 2011 at 11:30 PM, hoelzro <
reply@reply.github.com>wrote:

Lua 5.1.4, OS X 10.6

nathanaeljones reply@reply.github.com wrote:

What platform are you running? Versions?

Sent from my iPad

On Sep 5, 2011, at 10:37 PM, hoelzroreply@reply.github.com wrote:

Ok, I did some more testing, and it turns out this feature works fine; my
example is just broken. If you try this:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

...it works fine.

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAk5laO4ACgkQUoGaR6SGEaq3HgCeOI7Ub6RVOQsXbPrr8Egq47zG
T5MAn2Zzrei+Imt6c5t+CenKozfwsKJq
=pyz2
-----END PGP SIGNATURE-----

@lilith
Copy link

lilith commented Sep 6, 2011

I installed 5.1.4, cleaned and rebuild pluto, got exactly the same result.

Also, the tests fail... what happens when you run make test? I get:

Nathanael:pluto nathanael$ make test
./pptest
pptest.lua:167: attempt to index global 'outfile' (a nil value)
./puptest
attempt to call a nil value

On Tue, Sep 6, 2011 at 2:27 AM, hoelzro <
reply@reply.github.com>wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The change is this:

perms = { [1] = coroutine.yield }

Have you tried this on Lua 5.1.4? Also, make sure you're using the same
version of Lua that you compiled Pluto against; it's very sensitive to
binary changes.

  • -Rob

On Sep 5, 2011, at 5:56 PM, nathanaeljones wrote:

On Lua 5.1.3 using the latest from the 'master' branch of your repo, I
get

true 1
true 4
true 9
true 16
true 25
Segmentation fault

I'm using the code you sent me:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

What was the change you made to the example?

On Mon, Sep 5, 2011 at 11:30 PM, hoelzro <
reply@reply.github.com>wrote:

Lua 5.1.4, OS X 10.6

nathanaeljones reply@reply.github.com wrote:

What platform are you running? Versions?

Sent from my iPad

On Sep 5, 2011, at 10:37 PM, hoelzroreply@reply.github.com wrote:

Ok, I did some more testing, and it turns out this feature works fine;
my
example is just broken. If you try this:

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 10 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, coro)
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s)
for i = 1, 5 do
print(coroutine.resume(coro))
end

...it works fine.

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

Reply to this email directly or view it on GitHub:
#6 (comment)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAk5laO4ACgkQUoGaR6SGEaq3HgCeOI7Ub6RVOQsXbPrr8Egq47zG
T5MAn2Zzrei+Imt6c5t+CenKozfwsKJq
=pyz2
-----END PGP SIGNATURE-----

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

I get success...try changing line 166:

outfile = io.open("test.plh", "wb")

to this:

outfile = assert(io.open("test.plh", "wb"))

and tell me what results you get.

@lilith
Copy link

lilith commented Sep 6, 2011

Turns out test.plh was locked somehow. (your code helped diagnose that)..

pptest now runs, still getting

./puptest
attempt to call a nil value

On Tue, Sep 6, 2011 at 3:00 AM, hoelzro <
reply@reply.github.com>wrote:

I get success...try changing line 166:

outfile = io.open("test.plh", "wb")

to this:

outfile = assert(io.open("test.plh", "wb"))

and tell me what results you get.

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

This is during make test? Is that the only output it gives?

@lilith
Copy link

lilith commented Sep 6, 2011

No, the entire output is:

Nathanael:pluto nathanael$ make test
./pptest
./puptest
attempt to call a nil value

Also, found out something new...

The difference between the seg fault and my corruption error
(["\000\000\000\000"] = 3.6073928448386e-313;) is whether the coroutine is
nested in a table or is the root object...

The following code gives me an "bad argument #1 to 'resume' (coroutine
expected)" error instead of segfaulting.

local pluto = require 'pluto'

local coro = coroutine.create(function()
for i = 1, 20 do
coroutine.yield(i * i)
end
end)

for i = 1, 5 do
print(coroutine.resume(coro))
end
local perms = {
[coroutine.yield] = 1,
}
local s = pluto.persist(perms, {co = coro})
perms = { [1] = coroutine.yield }
coro = pluto.unpersist(perms, s).co
for i = 1, 5 do
print(coroutine.resume(coro))
end

On Tue, Sep 6, 2011 at 3:08 AM, hoelzro <
reply@reply.github.com>wrote:

This is during make test? Is that the only output it gives?

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

How strange...that same code works fine on my machine. How did you install Lua? By hand, or via a package manager?

@lilith
Copy link

lilith commented Sep 6, 2011

By hand... Make macosx, sudo make install...

I have installed 5.2, 5.1.4,5.1.3,5.1.4 in that order... I'm assuming they overwrite each other properly. At least lua -v is correct each time.

Sent from my iPad

On Sep 6, 2011, at 3:29 AM, hoelzroreply@reply.github.com wrote:

How strange...that same code works fine on my machine. How did you install Lua? By hand, or via a package manager?

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

I wouldn't make such an assumption...where have you installed Lua to?

@lilith
Copy link

lilith commented Sep 6, 2011

Always the default, /usr/local/.

I copied the shell output for 'make install' for all the versions. 5.2 only
seems to differ in that 'lua.hpp' goes into /usr/local/include instead of
/usr/local/etc/

I ran make uninstall for each version before running make install for 5.1.4

Lua 5.2 alpha
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib
/usr/local/man/man1 /usr/local/share/lua/5.2 /usr/local/lib/lua/5.2
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp
/usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
#cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1

Lua 5.1.3
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib
/usr/local/man/man1 /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h
../etc/lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1

Lua 5.1.4
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib
/usr/local/man/man1 /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h
../etc/lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1

On Tue, Sep 6, 2011 at 3:49 AM, hoelzro <
reply@reply.github.com>wrote:

I wouldn't make such an assumption...where have you installed Lua to?

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

Try installing Lua to a non-default location, like ~/lua.

@lilith
Copy link

lilith commented Sep 6, 2011

I think it might be with my installation of pluto. Apparently I still had
the luarocks version around. I uninstalled it, and re-installed the github
version.

Or, at least, I thought I did. I misread the makefile and assumed it was
compiling directly to /usr/local/lib/lua/5.1/pluto.so.

Instead, I'm only seeing pluto.dylib. How should I go about installing this
so lua will pick it up automatically?

On Tue, Sep 6, 2011 at 4:09 AM, hoelzro <
reply@reply.github.com>wrote:

Try installing Lua to a non-default location, like ~/lua.

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

See, this is something that frustrates me about Lua on OS X. I believe that Lua should be built to load dylibs, but a lot of scripts have it load .so files. sigh

For the time being, run this to at least test things out:

export LUA_CPATH='?.dylib'

@lilith
Copy link

lilith commented Sep 6, 2011

Wow.. thanks, it's working!

I can't believe it ended being something so stupid... Serves me right for
trying to debug something after midnight... It's almost 5am, I'm gonna grab
some sleep.

I really appreciate your help!

Nathanael

On Tue, Sep 6, 2011 at 4:35 AM, hoelzro <
reply@reply.github.com>wrote:

See, this is something that frustrates me about Lua on OS X. I believe
that Lua should be built to load dylibs, but a lot of scripts have it load
.so files. sigh

For the time being, run this to at least test things out:

export LUA_CPATH='?.dylib'

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 6, 2011

Happy to help! Glad you got it working! Let me know if you have any more questions about Pluto.

Of course, if you end up writing any patches, they would be most welcome. =)

@lilith
Copy link

lilith commented Sep 6, 2011

Thanks :) I'm making great progress, already got a basic web UI going.

Have you used xavante or wsapi at all? I can't figure out how to get an
Orbit app to run without having the 'script.lua' in the URL.. I'd use the
'orbit' command, but it doesn't support reloading.

On Tue, Sep 6, 2011 at 5:18 AM, hoelzro <
reply@reply.github.com>wrote:

Happy to help! Glad you got it working! Let me know if you have any more
questions about Pluto.

Of course, if you end up writing any patches, they would be most welcome.
=)

Reply to this email directly or view it on GitHub:
#6 (comment)

@hoelzro
Copy link
Owner Author

hoelzro commented Sep 7, 2011

I haven't done any web development with Lua (unfortunately); why don't you join the #lua channel on Freenode when you have some time? A lot of Lua people are there, and I'm sure someone there could help you out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants