Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

While writing a test on work I hit a bug in perl. Normally if recv is interrupted by a signal it returns undef and sets $! to EINTR. In my case I had failure because $! was set to zero. It took me some time to reproduce conditions in which it happens, but finally I've got it boiled down to the following:

use strict; use warnings; use IO::Socket::INET; my $srv = IO::Socket::INET->new( LocalAddr => '', LocalPort => 7777, ReuseAddr => 1, Listen => 1, ) or die $!; my $sock = IO::Socket::INET->new( PeerAddr => '', PeerPort => 7777, ) or die $!; my $cli = $srv->accept or die $!; my $sock2 = IO::Socket::INET->new( PeerAddr => '', PeerPort => 7777, ) or die $!; my $cli2 = $srv->accept or die $!; local $SIG{ALRM} = sub { $sock->send( "hi\n", 0 ); }; alarm 2; my $res; use Data::Dumper; $res = $sock2->recv( my $buf, 1024 ) or die Dumper [ $res, $!, 0 + $!, + ]; __END__ $VAR1 = [ undef, '', '0' ];

The trick was to establish two connections to the same peer, with only one connection I was getting correct result. Apparently this was fixed somewhere in 5.13, because if I run this with 5.14.2 it returns expected result, which is:

$VAR1 = [ undef, 'Interrupted system call', '4' ];

That's the downside of using stable Debian -- you're hitting bugs that were already found and fixed years ago. I couldn't find it in RT though, so if somebody by any chance know what I'm talking about and can point me to the ticket or commit in git it would be much appreciated. I naturally fixed the problem in my module with:

my $ret = $self->{_socket}->recv( my $buffer, 131072 ); unless ( defined $ret ) { - next if $! == EINTR; + next if $! == EINTR or $! == 0; confess "Error reading reply from server: $!"; }
But now I have some doubts -- maybe recv sets $! to 0 for some other errors too.

Update: for the record, the commit that fixes the problem is d016601

In reply to Rediscovering fixed bugs by zwon

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the monks are chillaxin'...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2018-06-18 16:34 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (110 votes). Check out past polls.