Neopallium / lua-zmq

Lua zeromq2 binding
http://github.com/Neopallium/lua-zmq
MIT License
151 stars 36 forks source link

malloc_error_break on exit #14

Closed randrews closed 13 years ago

randrews commented 13 years ago

I've got a program that uses req / rep sockets that works totally fine with the iamaleskey version, and explodes with a malloc error on this version.

Here's the client:

require 'zmq'

ctx = zmq.init(1)
socket = ctx:socket(zmq.REQ)
socket:connect 'tcp://localhost:4568'
k = 0

while k < 10 do
   msg = string.format('ping %d', k)
   socket:send(msg)
   print(socket:recv())
   k = k + 1
   os.execute 'sleep 1'
end

socket:close()
ctx:term()

And the server:

require 'zmq'

ctx = zmq.init(1)
socket = ctx:socket(zmq.REP)
socket:bind 'tcp://*:4568'
n = 0

while true do
   s = socket:recv()
   print(string.format('Echoing %q', s))
   socket:send(s)
end

socket:close()
ctx:term()

I'm using zmq 2.1.7 on OS X Lion, Lua 5.1.4, and it fails with this:

lua(1373,0x7fff7d9e2960) malloc: *** error for object 0x1000bdc00: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
Neopallium commented 13 years ago

Which one crashes the client or the server? Also can you please provide a backtrace. I can not reproduce the crash on Linux and don't have a Mac to test on.

randrews commented 13 years ago

Sorry, should have said that. The client crashes, but it crashes on exit; it sends all the messages just fine. The only stack information I have is that error I pasted in.

Neopallium commented 13 years ago

Please run the client using gdb to get a backtrace: $ gdb lua (gdb) run client.lua

randrews commented 13 years ago

Not sure how useful this is, but here you go:

ping 1  nil
ping 2  nil
ping 3  nil
ping 4  nil
ping 5  nil
ping 6  nil
ping 7  nil
ping 8  nil
ping 9  nil
ping 10 nil
lua(9081,0x7fff7d9e2960) malloc: *** error for object 0x1000bdc00: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGABRT, Aborted.
0x00007fff8f991ce2 in __pthread_kill ()

Not much of a stack trace, sorry. :)

Neopallium commented 13 years ago

Sorry I forgot you will need to use another gdb command to get the backtrace after the crash: $ gdb lua (gdb) run client.lua ------- wait for crash (gdb) thread apply all backtrace ------ that command will display backtrace for all running threads.

How are you compiling lua-zmq? Using LuaRocks or the CMake build?

Can you provide the build output from my lua-zmq and from iamaleskey's version. I think this might be a problem with compiler flags.

Maybe an easier way would be to replace iamaleskey's zmq.c file with src/pre_generated-zmq.nobj.c and use his makefile to build the .so file and see if it still crashes.

Neopallium commented 13 years ago

Looks like this is a common problem on OSX: http://lua-users.org/lists/lua-l/2009-10/msg00136.html

Did you recently recompile/reinstall Lua?

Also someone on that thread provided this link to pre-compiled Lua binaries: http://pdb.finkproject.org/pdb/package.php/lua51

With what I am reading online about this error it seems to be a problem with how Lua is compiled on OSX, or maybe lua-zmq is being linked to the wrong version of the Lua VM core (liblua.dylib file).

anyways I hope this info helps, let me know how it goes.

Neopallium commented 13 years ago

Looks like the Lua from MacPorts should also work, since they include some fixes to the lua Makefiles for this issue: http://www.macports.org/ports.php?by=name&substr=lua