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

Signal handling issue with ruby 1.8.7 #8

Open
fjnl opened this issue Jun 26, 2011 · 1 comment
Open

Signal handling issue with ruby 1.8.7 #8

fjnl opened this issue Jun 26, 2011 · 1 comment

Comments

@fjnl
Copy link

fjnl commented Jun 26, 2011

With ruby 1.8.7, zmq 2.1.7 and rbzmq 2.1.3, I notice that rbzmq has signal handling problem.
With ruby 1.9.2, this problem is not occurred.

Reproduction code is below.

require 'rubygems'
require 'zmq'

c = ZMQ::Context.new
s = c.socket(ZMQ::PULL)
s.bind('ipc:///tmp/a')

begin
  puts s.recv
ensure
  $stderr.puts 'ensure'
  s.close
  c.close
end

When I input Ctrl-c and terminate this program while blocking in s.recv,
I expect the ensure closure is run and 'ensure' is shown in the terminal but actual output is below.

$ ruby intr.rb
^Cintr.rb:11: Interrupt

The line number of Interrupt is strange. Line 11 is '$stderr.puts ...'.
I think EINTR is ignored because ruby vm will handle it.
I've created a small patch for socket_recv. It seems fine but I don't know whether this is the best way.

diff --git a/rbzmq.c b/rbzmq.c
index 8164c93..d1929fc 100644
--- a/rbzmq.c
+++ b/rbzmq.c
@@ -1603,7 +1603,7 @@ static VALUE socket_recv (int argc_, VALUE* argv_, VALUE self_)
     else
 #endif
         rc = zmq_recv (s, &msg, flags);
-    if (rc != 0 && zmq_errno () == EAGAIN) {
+    if (rc != 0 && zmq_errno () == EAGAIN || zmq_errno () == EINTR) {
         rc = zmq_msg_close (&msg);
         assert (rc == 0);
         return Qnil;
@bwbuchanan
Copy link
Contributor

Can you send a pull request, please?

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