chuckremes / ffi-rzmq

FFI bindings for ZeroMQ so the library can be used under JRuby and other FFI-compliant ruby runtimes
242 stars 62 forks source link

ffi-rzmq on winxp64 with zeromq-4.0.3 - WSAEINVAL - Invalid argument #106

Closed deployable closed 9 years ago

deployable commented 10 years ago

libzqm 4.0.3 built with mingw (disabled -Werror to get build to work due to unsigned int warn) ffi-rzmq-core 1.0.1 (gem) ffi-rzmq 2.0.0 (github head)

On calling on ctx = ZMQ::Context.new an exception is thrown:

c:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-rzmq-2.0.0/lib/ffi-rzmq/util.rb:73:in raise_error': msg [Invalid argument], error code [22], rc [-1] (ZMQ::ContextError) from c:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-rzmq-2.0.0/lib/ffi-rzmq/util.rb:56:inerror_check' from c:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-rzmq-2.0.0/lib/ffi-rzmq/context.rb:70:in initialize' from zmq.msgsrv.rb:12:innew' from zmq.msgsrv.rb:12:in `

'

Which amounts the ruby library trying to run zmq-ctx-set setting the ZMQ_MAX_SOCKETS option to the default value of 1024, or any other supplied value. I had to skip the code that zmq-ctx-set when left at default the context/socket works as normal with the C default max_sockets, which is also 1024.

A zmq-ctx-set for IO_THREADS works as expected.

chuckremes commented 10 years ago

@deployable Can you provide more details on how you built libzmq 4.0.3 with mingw? I installed the latest devkit (a 32-bit mingw package from rubyinstaller.org) and it dies on building 4.0.3 almost immediately. It chokes on IN6_ADDR so I can't make it very far to troubleshoot this issue. Any insight you can provide would be welcome.

deployable commented 10 years ago

@chuckremes sorry that was a bit of a rushed note..

I ran the build via the ruby 23bit dev kits msys shell

start C:\programs\lang\ruby\Ruby193\DevKit\msys.bat

Some vars to make this easier

build_dir="c:/dply/build"
ruby_dir="c:/programs/lang/ruby/Ruby193"
zmq_test_args="tcp://10.1.1.70:5678 1000 100000"

Build

cd $build_dir
wget http://download.zeromq.org/zeromq-4.0.3.zip
7z x zeromq-4.0.3.zip
cd $build_dir/zeromq-4.0.3/
./configure --prefix=c:/programs/dev/zeromq-4.0.3

Either fix src/socket_base.cpp or disable -Werror in CPPFLAGS in Makefile https://github.com/zeromq/libzmq/commit/fd8d6d471f486fd2392a17774f4c26e99af21f66

make

Test

./perf/local_lat  $zmq_test_args &
./perf/remote_lat $zmq_test_args
./perf/local_thr  $zmq_test_args &
./perf/remote_thr $zmq_test_args

Install the gem

$ruby_dir/bin/gem install ffi-rzmq
mkdir $ruby_dir/lib/ruby/gems/1.9.1/gems/ffi-rzmq-core-1.0.1/ext
cp $build_dir/zeromq-4.0.3/src/.libs/libzmq.dll $ruby_dir/lib/ruby/gems/1.9.1/gems/ffi-rzmq-core-1.0.1/ext/

Then using the client and server examples from https://github.com/chuckremes/ffi-rzmq:

$ruby_dir/bin/ruby ffi-rzmq.srv.rb $zmq_test_args

produces

c:/programs/lang/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-rzmq-2.0.0/lib/ffi-rzmq/util.rb:73:in `raise_error': msg [Invalid argument], error code [22], rc [-1] (ZMQ::ContextError)
      from c:/programs/lang/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-rzmq-2.0.0/lib/ffi-rzmq/util.rb:56:in `error_check'
      from c:/programs/lang/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-rzmq-2.0.0/lib/ffi-rzmq/context.rb:70:in `initialize'

      from ffi-rzmq.srv.rb:13:in `new'
      from ffi-rzmq.srv.rb:13:in `<main>'

Commenting out the max socket setter in lib/ffi-rzmq/context.rb (which is defaulted in zmq anyway).

  #rc = LibZMQ.zmq_ctx_set(@context, ZMQ::MAX_SOCKETS, @max_sockets)
  #ZMQ::Util.error_check 'zmq_ctx_set', rc

I've submitted a pull with updated srv and cli code to get the readme examples working https://github.com/chuckremes/ffi-rzmq/pull/108

Then the server and cli work

$ruby_dir/bin/ruby ffi-rzmq.srv.rb $zmq_test_args &
deployable commented 10 years ago

Also the default in zmq has gone down one... https://github.com/zeromq/libzmq/commit/7c514294408c22117c4a0553e5d36d18cac23928

The way context.rb's initializer is currently structured, it doesn't lend it's self to just leaving the library default unless one is specifically set. Not the solution to the problem but might be easier not to duplicate a default in ruby?

zataak commented 10 years ago

Any ETA on the resolution of this issue?

chuckremes commented 10 years ago

I have duplicated the problem on my local machine. Working on it now.

chuckremes commented 10 years ago

Looks like an issue with the library. Running "make check" shows that "test_ctx_options" fails which includes a test to verify that "ctx_get(context, MAX_SOCKETS) == ZMQ_MAX_SOCKETS" is true.

For some reason the default max sockets is set to 63 even though the ZMQ_MAX_SOCKETS constant is 1023. I asked on the mailing list for some insight, so hopefully someone will have an idea.

In the meantime, setting a lower default fixes the issue:

context = ZMQ::Context.new(:max_sockets => 63) ...