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

ZMQ::LibZMQ3 somehow breaks perl's die semantics with infinite poll(...) loop #50

Open
megahall opened this issue Mar 12, 2014 · 5 comments

Comments

@megahall
Copy link

Something gets broken inside of perl, when certain functions from ZMQ::LibZMQ3 are added into the code. It does not matter if the functions ever actually execute. This test case should get stuck forever instead of finishing the die process on Mac OS X. I have seen it happen sometimes on Linux as well but not as reliably.

I am guessing, referencing certain functions must cause a ZMQ event loop to be started, but there is no code to ensure the loop is ended and doesn't become infinite when perl tries to shut down. When tracing the code with dtruss, etc. you can see it gets stuck in some kind of poll(...).

When a custom __DIE__ handler is registered, it seems possible to work around the issue.

#!/usr/bin/env perl

use strict;
use warnings FATAL => 'all';

use ZMQ::LibZMQ3;
use ZMQ::Constants qw(:all);

# ZMQ context
my $zmq_ctx    = zmq_ctx_new();
my $zmq_socket = zmq_socket($zmq_ctx, ZMQ_PUB) or die "zmq_socket failed: $!";
zmq_bind($zmq_socket, "tcp://*:31337") and die "zmq_bind failed: $!";

sub handle_die {
    my ($message) = @_;

    # $^S : parser state: undef during parse, 1 when running eval, 0 otherwise
    die @_ if $^S;

    print "got here\n";
    zmq_close($zmq_socket) if $zmq_socket;
    zmq_ctx_destroy($zmq_ctx) if $zmq_ctx;

    die @_;
}

die "should be able to die at this point but it gets stuck";

$SIG{__DIE__} = \&handle_die;

my $data = "foo bar baz boo";
my $message = zmq_msg_init_data($data);
zmq_send($zmq_socket, $message) or die "zmq_msg_send failed: $!";
#zmq_msg_close($message);

die "but instead we can only die from this point due to stuck poll(...) loop";

exit(0);
@lestrrat
Copy link
Collaborator

I tried it on my OS X, perl 5.18.2 (no thread), zeromq-3.2.4, ZMQ-LibZMQ3 HEAD, and got "should be able to die at this point but it gets stuck";

@megahall
Copy link
Author

Right. It dies there, then it doesn't actually die, because the ZMQ event thread is holding perl open when it should be able to exit.

Sent from my mobile device.

On March 12, 2014 2:46:58 PM PDT, lestrrat notifications@github.com wrote:

I tried it on my OS X, zeromq-3.2.4, ZMQ-LibZMQ3 HEAD, and got "should
be able to die at this point but it gets stuck";


Reply to this email directly or view it on GitHub:
#50 (comment)

@lestrrat
Copy link
Collaborator

I'm confused. It died as the message implied. it exited.

@megahall
Copy link
Author

Interesting. On my system it would execute the die, print the message, but still stay running. I'll check on it.

Sent from my mobile device.

On March 12, 2014 3:26:37 PM PDT, lestrrat notifications@github.com wrote:

I'm confused. It died as the message implied. it exited.


Reply to this email directly or view it on GitHub:
#50 (comment)

@domm
Copy link
Contributor

domm commented Mar 13, 2014

We had some similar symptoms which were cause by indefinite linger settings. Maybe that's part of the problem? (I didn't run or check your code, so this is just a shot in the dark)

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

3 participants