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

Already on GitHub? Sign in to your account

Invalid Socket Option with zbusd on Lion #4

Closed
andrewstarks opened this Issue May 9, 2012 · 10 comments

Comments

Projects
None yet
2 participants

On a Lion install, which has ZMQ, Lua-ZMQ and zbusd installed (from luarocks, and luarocks/luajit installed from homebrew):

zbusd   ZMQ_Socket: 0x000fcb48, flags=1 ZMQ_Socket: 0x0022d040, flags=1
/usr/local/bin/luajit: [string "zmq"]:1006: Invalid socket option.
stack traceback:
    [C]: in function 'error'
    [string "zmq"]:1006: in function 'getopt'
    /usr/local/share/lua/5.1//zbus/util.lua:31: in function 'zmq_read_io'
    /usr/local/share/lua/5.1//zbus/broker.lua:403: in function 'loop'
    /usr/local/lib/luarocks/rocks/zbus/scm-1/bin/zbusd.lua:7: in main chunk
    [C]: ?

I'm sure that it's something dumb on my part, but even after walking through the source code, I don't know what to check. I will say that it appears that zbusd.lua has a reg_url variable that I never see used. Here is the source of that file:

local broker = require'zbus.broker'.new{
  reg_url = arg[1],
  debug = true,
  log = function(...) print('zbusd',...) end
}
broker:loop()

Let me know if there is anything that I can do to help clarify!

Okay... so I reinstalled. I'm still broken, but I got this as an error now:

zbusd   ZMQ_Socket: 0x7f8320d01070, flags=1 ZMQ_Socket: 0x7f8320d00770, flags=1
/usr/local/bin/lua: /usr/local/share/lua/5.1//zbus/util.lua:12: bad argument #2 to 'new' (number expected, got nil)
stack traceback:
    [C]: in function 'new'
    /usr/local/share/lua/5.1//zbus/util.lua:12: in function 'zmq_read_io'
    /usr/local/share/lua/5.1//zbus/broker.lua:402: in function 'loop'
    ...sr/local/lib/luarocks/rocks/zbus/scm-1/bin/zbusd.lua:7: in main chunk
    [C]: ?

Upon digging, I found that if I add the following modification to utils.lua:

local print = print
module('zbus.util')

local zmq_read_io = 
   function(zsock,on_readable)
      local getopt = zsock.getopt
print("TEST",zsock,zmq.FD,getopt(zsock,zmq.FD))

etc...

I get this:

[Lisa:/] andrew% zbusd.lua
zbusd   ZMQ_Socket: 0x7ff53a501b60, flags=1 ZMQ_Socket: 0x7ff53a501280, flags=1
TEST    ZMQ_Socket: 0x7ff53a501280, flags=1 14  nil Invalid socket option.
/usr/local/bin/lua: /usr/local/share/lua/5.1//zbus/util.lua:13: bad argument #2 to 'new' (number expected, got nil)
stack traceback:
    [C]: in function 'new'
    /usr/local/share/lua/5.1//zbus/util.lua:13: in function 'zmq_read_io'
    /usr/local/share/lua/5.1//zbus/broker.lua:402: in function 'loop'
    ...sr/local/lib/luarocks/rocks/zbus/scm-1/bin/zbusd.lua:7: in main chunk
    [C]: ?

Okay. Sorry for the noise. Hopefully this helps.

@ghost ghost assigned lipp May 13, 2012

Owner

lipp commented May 13, 2012

Thanks for reporting. I just returned from holidays and will fix this the next days.

Owner

lipp commented May 14, 2012

Could you please look what
local v = zmq.version()
print(v[1],v[2],v[3])
outputs?
Maybe the zeromq version is outdated...

I was on vacation, as well. the above produced:

2 2 0

UPDATE:

I did try installing zmq head and that broke lua-zmq horribly. I believe that 2.2.0 is the correct version. Let me know if I can be of any help and thank you!

Owner

lipp commented May 21, 2012

OK, ... strange. I'd suggest to write a tiny test in C or C++ to see if the zmq_getsockopt has issues on OSX.
This is a small test which tries to read the ZMQ_FD sockopt:

https://gist.github.com/2761607

Owner

lipp commented May 21, 2012

btw: 2.2.0 should be fine!

I hate to be so helpless here, but would yo mind tossing me the compiler flags to link?

Here is the hacked up Makefile that I used:

CC = gcc-4.2
CFLAGS = -Wall -L/usr/local/lib -I/usr/local/include -I$(SRC_DIR)
LUAFLAGS = -lzmq -arch x86_64
EXEC= capi


SRC_DIR = ./src
OUTPUT_DIR = ./build

all: $(EXEC)

clean:
    -rm $(OUTPUT_DIR)/test
    -rm $(OUTPUT_DIR)/*.exe

$(EXEC): 
    $(CC) $(CFLAGS) $(LUAFLAGS) -o $(OUTPUT_DIR)/$(EXEC) $(SRC_DIR)/test_opt.cpp

It is most likely fatally wrong, but in case it's not, this is what was barfed when I ran it:

gcc-4.2 -Wall -L/usr/local/lib -I/usr/local/include -I./src -lzmq -arch x86_64 -o ./build/capi ./src/test_opt.cpp
Undefined symbols for architecture x86_64:
  "vtable for std::exception", referenced from:
      std::exception::exception()in ccy8bLh9.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "std::exception::~exception()", referenced from:
      zmq::error_t::error_t()in ccy8bLh9.o
      zmq::error_t::~error_t()in ccy8bLh9.o
      zmq::error_t::~error_t()in ccy8bLh9.o
  "___cxa_allocate_exception", referenced from:
      zmq::context_t::context_t(int)in ccy8bLh9.o
      zmq::socket_t::socket_t(zmq::context_t&, int)in ccy8bLh9.o
      zmq::socket_t::bind(char const*)in ccy8bLh9.o
      zmq::socket_t::getsockopt(int, void*, unsigned long*)in ccy8bLh9.o
      zmq::socket_t::close()    in ccy8bLh9.o
  "___cxa_throw", referenced from:
      zmq::context_t::context_t(int)in ccy8bLh9.o
      zmq::socket_t::socket_t(zmq::context_t&, int)in ccy8bLh9.o
      zmq::socket_t::bind(char const*)in ccy8bLh9.o
      zmq::socket_t::getsockopt(int, void*, unsigned long*)in ccy8bLh9.o
      zmq::socket_t::close()    in ccy8bLh9.o
  "___cxa_free_exception", referenced from:
      zmq::context_t::context_t(int)in ccy8bLh9.o
      zmq::socket_t::socket_t(zmq::context_t&, int)in ccy8bLh9.o
      zmq::socket_t::bind(char const*)in ccy8bLh9.o
      zmq::socket_t::getsockopt(int, void*, unsigned long*)in ccy8bLh9.o
      zmq::socket_t::close()    in ccy8bLh9.o
  "___cxa_call_unexpected", referenced from:
      zmq::error_t::what() constin ccy8bLh9.o
  "operator delete(void*)", referenced from:
      zmq::error_t::~error_t()in ccy8bLh9.o
      zmq::error_t::~error_t()in ccy8bLh9.o
  "vtable for __cxxabiv1::__si_class_type_info", referenced from:
      typeinfo for zmq::error_tin ccy8bLh9.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "typeinfo for std::exception", referenced from:
      typeinfo for zmq::error_tin ccy8bLh9.o
  "___gxx_personality_v0", referenced from:
      Dwarf Exception Unwind Info (__eh_frame) in ccy8bLh9.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [capi] Error 1
Owner

lipp commented May 22, 2012

This works on my ubuntu machine (no Makefile at all) with no complains:
g++ test_opt.cpp -lzmq -o test_opt

Your gcc is fairly old though. is this the recent xcode gcc/toolchain?
Hope this helps

Owner

lipp commented Jun 26, 2012

Hello Andrew!
I just wanted to keep you informed about zbus:

I droped dependency on on zeromq and just require luasocket and lua-ev at this point (branch name: "without_zmq").
The new version seems to work quite good.

I will work more regularly on zbus the next weeks, to improve code, write more test and doc, since it will become IPC backbone on my employers embedded devices.

Maybe you will give it a try...
Regards

g++ test_opt.cpp -lzmq -o test_opt worked, returning 0.

I'll check out the new version...

@lipp lipp closed this Apr 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment