Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

IO::Socket::UNIX plus syswrite plus eval fails?

by cavac (Parson)
on Jun 02, 2021 at 11:46 UTC ( [id://11133414]=perlquestion: print w/replies, xml ) Need Help??

cavac has asked for the wisdom of the Perl Monks concerning the following question:

Either i found a bug or i'm doing something incredibly stupid (my guess is the "stupidity").

I'm using a non-blocking client with IO::Socket::UNIX. Sometimes the script just exits without any error message, even though i'm trying to catch that specific case with an eval. Here is the relevant code:

print "Write to backend $clientid\n"; my $written; eval { print "AAAA\n"; $written = syswrite($clients{$clientid}->{backendsocket}, $clients +{$clientid print "BBBB\n"; }; print "X\n"; if($EVAL_ERROR) { print "Backend write error: $EVAL_ERROR\n"; push @toremove, $clientid; next; }

Most of the time this works fine, but sometimes i just get:

Write to backend someclientid AAAA

And then i'm back at the command line without any additional message. Shouldn't eval catch any errors and prevent the script from exiting?

If something goes wrong in syswrite, i'd expect an output like this:

Write to backend someclientid AAAA X Backend write error: some_error_message

What am i doing wrong here?

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Replies are listed 'Best First'.
Re: IO::Socket::UNIX plus syswrite plus eval fails?
by Corion (Patriarch) on Jun 02, 2021 at 11:48 UTC

    Maybe your kernel is killing the process for some obscure reason? Does the shell have anything to say about the exit code?

    echo $?

    On the surface, I agree with you about eval catching that stuff, but if it is some signal, that wouldn't be caught by the eval.

      I got 141. Damn it, Jim, it's a SIGPIPE.

      Yeah, a $SIG{PIPE} = 'IGNORE'; seems to solve the problem.

      perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11133414]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found