lestrrat/ZeroMQ-Perl — Issue #25: Calling close on a socket twice causes fatal error "Invalid ZeroMQ::Raw::Socket object (perhaps you've already freed it?)"
Author: wolfsage
Created: 2011-12-13 18:43:45+00:00
State: open

If you close a ZeroM::Socket object twice, Perl dies:

Script:

#!/usr/bin/perl

use ZeroMQ qw(:all);

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

$sock->close;
$sock->close;

Output:

Invalid ZeroMQ::Raw::Socket object (perhaps you've already freed it?) at (eval 9) line 3.

This may not really be a 'bug' in the sense of the word and the real solution may be "Don't do that.". If you compare to IO::Socket::INET though; calling close twice just fills in $! with 'bad file descriptor' and returns undef.

I think emulating this behavior would be good.

If it turns out that we want to change the behavior... I'll also note here in this ticket that callling $cxt->term() twice also throws an error:

(Invalid ZeroMQ::Raw::Context object (perhaps you've already freed it?) at /usr/local/lib/perl5/site_perl/5.8.9/mach/ZeroMQ/Context.pm line 26)