Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

"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 simkserver.io: socket blocking state 1 2011-09-27 17:23:14,745 DEBUG simkserver.io: Client input call err Bad + file desc riptor line Proxy,127.0.0.1 2011-09-27 17:23:14,746 INFO simkserver.io: Client input: Proxy,127.0 +.0.1 2011-09-27 17:23:14,746 INFO simkserver: Connection is from proxy for + 127.0.0.1 2011-09-27 17:23:14,747 DEBUG simkserver.io: socket blocking state 1 2011-09-27 17:23:14,747 DEBUG simkserver.io: Client input call err Bad + file desc riptor line foo,3 2011-09-27 17:23:14,748 INFO simkserver.io: 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 simkserver.io: socket blocking state 1 2011-09-27 17:23:16,557 DEBUG simkserver.io: Client input call err Bad + file desc riptor line h1,h2 2011-09-27 17:23:16,574 INFO simkserver.io: Client input: h1,h2 2011-09-27 17:23:16,575 DEBUG simkserver.io: socket blocking state 1 2011-09-27 17:23:16,575 DEBUG simkserver.io: Client input call err [em +pty] line [undef] 2011-09-27 17:23:16,576 DEBUG simkserver.io: 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.)

Comment on "Impossible" socket error return
Select or Download Code
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.

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.
Reaped: Re: "Impossible" socket error return
by NodeReaper (Curate) on Sep 28, 2011 at 12:53 UTC
Reaped: Re: "Impossible" socket error return
by NodeReaper (Curate) on Sep 29, 2011 at 13:16 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://928200]
Approved by ww
Front-paged by MidLifeXis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-29 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls