{"issue":{"created_at":"2011-12-13T18:43:45Z","state":"open","updated_at":"2011-12-14T15:01:39Z","user":{"gravatar_id":"ccd0005cf6435d68b01e37caceb6b187","id":643871,"url":"https://api.github.com/users/wolfsage","login":"wolfsage","avatar_url":"https://secure.gravatar.com/avatar/ccd0005cf6435d68b01e37caceb6b187?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":2,"body":"If you close a ZeroM::Socket object twice, Perl dies:\r\n\r\nScript:\r\n\r\n    #!/usr/bin/perl\r\n    \r\n    use ZeroMQ qw(:all);\r\n    \r\n    my $cxt = ZeroMQ::Context->new();\r\n    my $sock = $cxt->socket(ZMQ_SUB);\r\n    \r\n    $sock->close;\r\n    $sock->close;\r\n\r\nOutput:\r\n\r\n    Invalid ZeroMQ::Raw::Socket object (perhaps you've already freed it?) at (eval 9) line 3.\r\n\r\nThis 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.\r\n\r\nI think emulating this behavior would be good.\r\n\r\nIf 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:\r\n\r\n    (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)","assignee":null,"id":2541278,"number":25,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"title":"Calling close on a socket twice causes fatal error \"Invalid ZeroMQ::Raw::Socket object (perhaps you've already freed it?)\"","html_url":"https://github.com/lestrrat/ZeroMQ-Perl/issues/25","closed_at":null,"url":"https://api.github.com/repos/lestrrat/ZeroMQ-Perl/issues/25","milestone":null},"action":"created","comment":{"created_at":"2011-12-14T15:01:39Z","updated_at":"2011-12-14T15:01:39Z","user":{"gravatar_id":"ccd0005cf6435d68b01e37caceb6b187","id":643871,"url":"https://api.github.com/users/wolfsage","login":"wolfsage","avatar_url":"https://secure.gravatar.com/avatar/ccd0005cf6435d68b01e37caceb6b187?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"http://api.zeromq.org/2-1:zmq-close and http://api.zeromq.org/2-1:zmq-term both behave this way - they set errno and return -1. I don't know how close you were trying to emulate the interfaces of the individual design, I just saw this in passing and thought I would report it.\r\n\r\nI could see arguments both way. I'm not saying I'm attempting to close the socket twice on purpose, so on the one hand having it die is good because it helps people find bugs in their programs. On the other hand, attempting to close a closed socket doesn't really need to be a fatal condition; it could be handled more gracefully.\r\n\r\nAlso, having an error like those above is not clear to developers working with the Perl ZeroMQ library what actually went wrong; so if you want to keep the errors it may be nice to have them Carp at least.\r\n\r\nThanks,\r\n\r\n-- Matthew Horsfall (alh)\r\n\r\n","id":3140618,"url":"https://api.github.com/repos/lestrrat/ZeroMQ-Perl/issues/comments/3140618"}}