chuckremes / ffi-rzmq

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

Upgrading from 0.9.6 to 1.0.0 hangs on application exit #80

Closed TvL2386 closed 11 years ago

TvL2386 commented 11 years ago

Hi chuckremes,

I've upgraded to ffi-rzmq 1.0.0 and notice a difference between the two. My scripts are now hanging on exit. I've created a gist to demonstrate it. https://gist.github.com/TvL2386/4739718

Unfortunately it won't work without broker and worker, but maybe it's clear to you what happens?

Is this wanted behaviour or can it be fixed?

TvL2386 commented 11 years ago

hmmm... I use RubyMine for development and running my gist in RubyMine makes it hang, and running it in a terminal will not. Running the script in a terminal the same way RubyMine does, makes it hang though. May give some clues:

ruby -e '$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)' test_client1.rb
chuckremes commented 11 years ago

The short answer is that this is desired behavior. When you exit without explicitly closing sockets and terminating the context your scripts could be dropping 0mq packets.

The longer explanation is this. If you do not close the sockets and terminate the context then the Ruby runtime will run a finalizer to do it for you. There is no ordering guarantee for finalizers, so a deadlock/hang is probable.

I recommend doing an explicit socket close and context termination to avoid the hang and to avoid improper termination of libzmq that might result in losing data.

On Feb 8, 2013, at 9:32 AM, Tom van leeuwen notifications@github.com wrote:

Hi chuckremes,

I've upgraded to ffi-rzmq 1.0.0 and notice a difference between the two. My scripts are now hanging on exit. I've created a gist to demonstrate it. https://gist.github.com/TvL2386/4739718

Is this wanted behaviour or can it be fixed?

— Reply to this email directly or view it on GitHub.

TvL2386 commented 11 years ago

I was afraid that would be the answer

chuckremes commented 11 years ago

Heh :)

It's either that or people will complain that the ruby bindings sometimes drop their 0mq packets without warning.

On Feb 8, 2013, at 10:04 AM, Tom van leeuwen notifications@github.com wrote:

I was afraid that would be the answer

— Reply to this email directly or view it on GitHub.

TvL2386 commented 11 years ago

Alright! It's clear and it's not gonna change, so closing the issue! Thanks chuckremes!