Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

"Impossible" socket error return

by dd-b (Monk)
on Sep 27, 2011 at 22:40 UTC ( #928200=perlquestion: print w/replies, xml ) Need Help??
dd-b has asked for the wisdom of the Perl Monks concerning the following question:

In a fairly simple server (simulator; the actual guts aren't there, just the server infrastructure) using INET sockets running on Centos, I'm getting <$sock> returning undef with $! blank. SIGPIPE is ignored. I'm running out of ideas.

This chunk of code is in a subroutine, called to do all the input from the client:

$iologger->debug("socket blocking state ", $sock->blocking()); my $l = <$sock>; my $err = $!; $iologger->debug("Client input call err ", safe($err), " line ", safe($l)); if (!defined($l)) { my $d = Dumper($sock); $iologger->debug("Socket at error: $d"); die "eiread failed: $err"; } $iologger->info("Client input: ", safe($l)); return $l;

("safe()" is a function that turns undef into "[undef]" and an empty string into "[empty]" and passes through a non-empty string; so the log shows more clearly what's happening.)

Log output below shows it reading a number of lines, down to "h1,h2", and then on the next read call getting undef back. How can it get undef back, without $! being set? (The "Bad file descriptor" messages are lingering $! values, being reported when <$sock> returned a value, and hence don't mean anythying. The code is logging the $! value even when it's not meaningful. Lazy debug code, okay?)

2011-09-27 17:23:14,723 INFO simkserver: Accepted cmdcnt 1 starttime +17:23:14 2011-09-27 17:23:14,744 DEBUG socket blocking state 1 2011-09-27 17:23:14,745 DEBUG Client input call err Bad + file desc riptor line Proxy, 2011-09-27 17:23:14,746 INFO Client input: Proxy,127.0 +.0.1 2011-09-27 17:23:14,746 INFO simkserver: Connection is from proxy for + 2011-09-27 17:23:14,747 DEBUG socket blocking state 1 2011-09-27 17:23:14,747 DEBUG Client input call err Bad + file desc riptor line foo,3 2011-09-27 17:23:14,748 INFO Client input: foo,3 2011-09-27 17:23:14,748 DEBUG simkserver: command foo arg1 3 2011-09-27 17:23:14,749 DEBUG socket blocking state 1 2011-09-27 17:23:16,557 DEBUG Client input call err Bad + file desc riptor line h1,h2 2011-09-27 17:23:16,574 INFO Client input: h1,h2 2011-09-27 17:23:16,575 DEBUG socket blocking state 1 2011-09-27 17:23:16,575 DEBUG Client input call err [em +pty] line [undef] 2011-09-27 17:23:16,576 DEBUG Socket at error: $VAR1 = +bless( \*S ymbol::GEN1, 'IO::Socket::INET' ); 2011-09-27 17:23:16,577 ERROR simkserver: Aborted transaction on excep +tion eirea d failed: at ./simkserver line 103, <GEN1> line 3.

(The logging calls are log4perl.)

Replies are listed 'Best First'.
Re: "Impossible" socket error return
by ikegami (Pope) on Sep 27, 2011 at 23:36 UTC

    How can it get undef back, without $! being set?

    readline (for which <$fh> is a shortcut) returns undef on end of file as well as on error.

    By the way, there's no way to know if $! is meaningful after readline because readline has no way of signaling an error occurred.

      Thanks! Yes, it was indeed the obvious. Bug in another bit entirely was causing it to disconnect at an inopportune moment.
Re: "Impossible" socket error return
by onelesd (Pilgrim) on Sep 27, 2011 at 22:51 UTC

    Looks to me like the client finished sending and disconnected, and you get undef when that happens.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://928200]
Approved by ww
Front-paged by MidLifeXis
[Lady_Aleena]: atcroft, the whole link thing might be a question for either or both the CPAN sites. search.cpan is cpansearch@perl. org, and metacpan doesn't have an email addy for the website itself.
Lady_Aleena just followed @metacpan on Twitter.
[atcroft]: I may just post a question about it later. *shrug*
[Lady_Aleena]: I wish I could have helped you further but I've never uploaded to cpan or metacpan so I don't know much.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-05-27 04:34 GMT
Find Nodes?
    Voting Booth?