lestrrat/ZeroMQ-Perl — Issue #20: $socket->bind() hangs if last operation in a script
Author: wolfsage
Created: 2011-11-02 18:40:15+00:00
State: open

Oddly, if $socket->bind() is the last operation in a script, the script hangs.

I've tested this on FreeBSD 7.3 with perl, v5.8.9 built for amd64-freebsd (non-threaded) and on Ubuntu 10.04.2 LTS with v5.10.1 (*) built for i486-linux-gnu-thread-multi

```perl
#!/usr/bin/perl

use strict;
use warnings;

use ZeroMQ qw(:all);

my $cxt = ZeroMQ::Context->new();
my $sock = $cxt->socket(ZMQ_PUB);

print "Binding\n";

# This blocks...
$sock->bind("tcp://*:3003");

# ... but if you uncomment the following line
# the program exits normally

# print "Done\n";

```

On FreeBSD, top shows the process as waiting in kqread and a bt with gdb shows this:
```
(gdb) bt
#0 0x0000000800d86cfc in kevent () from /lib/libc.so.7
#1 0x000000080111e0f6 in zmq::kqueue_t::loop () from /usr/local/lib/libzmq.so.1
#2 0x0000000801131eef in thread_routine () from /usr/local/lib/libzmq.so.1
#3 0x000000080064051d in pthread_getprio () from /usr/lib/libpthread.so
#4 0x0000000000000000 in ?? ()
```

Similar behavior happens if the bind call is within a sub, except that the print no longer causes normal exit:

```perl
#!/usr/bin/perl

use strict;
use warnings;

use ZeroMQ qw(:all);
use ZeroMQ::Raw;

my $ctxt = zmq_init(1);
my $sock = zmq_socket( $ctxt, ZMQ_PUB );

sub do_bind {
zmq_bind( $sock, "tcp://127.0.0.1:5551" );
}

print "Binding...\n";

do_bind();

print "Done\n";
```