Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #70487] Perl interpreter exits when calling print on a closed socket

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

Nov 13, 2009, 1:50 PM

Post #1 of 5 (280 views)
Permalink
[perl #70487] Perl interpreter exits when calling print on a closed socket

# New Ticket Created by kyle.getz [at] gmail
# Please include the string: [perl #70487]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=70487 >



This is a bug report for perl from kyle.getz [at] gmail,
generated with the help of perlbug 1.35 running under perl v5.8.5.


-----------------------------------------------------------------
[Please enter your report here]

If print is called on a closed socket, the Perl interpreter exits (even if
running in debugger mode). I have been able to repro this issue with
5.8.5, 5.10.1, and 5.11.1. In fact, I found an old bug report that covers
the exact same issue:

http://rt.perl.org/rt3/Public/Bug/Display.html?id=5833

That bug is marked as "resolved", but there's no resolution, only a problem
description. This leads me to believe that the problem has been around for
a while and is still not fixed.

Here is a test script that exercises the bug:

-----------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $socket = IO::Socket::INET->new(PeerAddr => 'www.perl.com',
PeerPort => 80,
Proto => 'tcp',
Type => SOCK_STREAM) or
die "Failed to connect to server: $@";

shutdown $socket, 2;
my $rc = print $socket 'foo';
print "print returned $rc\n";
-----------------------------------------------------------------------

If you comment out the line that shuts down the socket and you run the
script, the output is exactly what you'd expect:

kgetz [at] gen-cs10 work> ./client.pl
print returned 1
kgetz [at] gen-cs10 work>


If you reinstate that line, then this is the output:

kgetz [at] gen-cs10 work> ./client.pl
kgetz [at] gen-cs10 work>

The last print statement of the script is not executed because the entire
interpreter exits. No return code, no call to die.

So why the "high" priority? Well, the script above is a bit of a contrived
example - what kind of client shuts down a socket and then tries to send
data on it? Instead, consider a server that handles multiple client
connections. If a client disconnects while the server is writing data on the
socket, the *entire server shuts down without warning*.

Even if this problem was client-side only (which it's not), it's still a
major deal as it causes the interpreter to fail.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=high
---
This perlbug was built using Perl v5.8.5 in the Red Hat build system.
It is being executed now by Perl v5.8.5 - Thu Jun 12 10:21:42 CDT 2008.

Site configuration information for perl v5.8.5:

Configured by Red Hat, Inc. at Thu Jun 12 10:21:42 CDT 2008.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
Platform:
osname=linux, osvers=2.6.9-67.0.15.elvm, archname=x86_64-linux-thread-multi
uname='linux v20z-x86-64.home.local 2.6.9-67.0.15.elvm #1 wed may 7 13:53:04 edt 2008 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-O2 -g -pipe -m64 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root [at] localhos -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Dprivlib=/usr/lib/perl5/5.8.5 -Dsitelib=/usr/lib/perl5/site_perl/5.8.5 -Dvendorlib=/usr/lib/perl5/vendor_perl/5.8.5 -Darchlib=/usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi -Dsitearch=/usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi -Dvendorarch=/usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi -Darchname=x86_64-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O2 -g -pipe -m64',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-9)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='gcc', ldflags =''
libpth=/usr/local/lib64 /lib64 /usr/lib64
libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.3.4.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.3.4'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared'

Locally applied patches:


---
@INC for perl v5.8.5:
/usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi
/usr/lib/perl5/5.8.5
/usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi
/usr/lib64/perl5/site_perl/5.8.4/x86_64-linux-thread-multi
/usr/lib64/perl5/site_perl/5.8.3/x86_64-linux-thread-multi
/usr/lib64/perl5/site_perl/5.8.2/x86_64-linux-thread-multi
/usr/lib64/perl5/site_perl/5.8.1/x86_64-linux-thread-multi
/usr/lib64/perl5/site_perl/5.8.0/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl/5.8.4
/usr/lib/perl5/site_perl/5.8.3
/usr/lib/perl5/site_perl/5.8.2
/usr/lib/perl5/site_perl/5.8.1
/usr/lib/perl5/site_perl/5.8.0
/usr/lib/perl5/site_perl
/usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi
/usr/lib64/perl5/vendor_perl/5.8.4/x86_64-linux-thread-multi
/usr/lib64/perl5/vendor_perl/5.8.3/x86_64-linux-thread-multi
/usr/lib64/perl5/vendor_perl/5.8.2/x86_64-linux-thread-multi
/usr/lib64/perl5/vendor_perl/5.8.1/x86_64-linux-thread-multi
/usr/lib64/perl5/vendor_perl/5.8.0/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl/5.8.4
/usr/lib/perl5/vendor_perl/5.8.3
/usr/lib/perl5/vendor_perl/5.8.2
/usr/lib/perl5/vendor_perl/5.8.1
/usr/lib/perl5/vendor_perl/5.8.0
/usr/lib/perl5/vendor_perl
.

---
Environment for perl v5.8.5:
HOME=/u/kgetz
LANG=en_US.UTF-8
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/bin:/usr/X11R6/bin:/u/kgetz/bin:/u/qa/tools
PERL_BADLANG (unset)
SHELL=/bin/bash


perlbug-followup at perl

Nov 14, 2009, 7:37 AM

Post #2 of 5 (261 views)
Permalink
[perl #70487] Perl interpreter exits when calling print on a closed socket [In reply to]

I confirm this bug exists on 5.10.0, 5.10.1, 5.11.0 and 5.11.1 on my
Linux system.

A better example is the following, as it shows that even eval() doesn't
prevent the interpreter exit:

##################
use strict;
use warnings;
use IO::Socket::INET;

my $socket = IO::Socket::INET->new(PeerAddr => 'www.perl.com',
PeerPort => 80,
Proto => 'tcp',
Type => SOCK_STREAM) or
die "Failed to connect to server: $!";

my $rc = shutdown $socket, 2;
print "socket shutdown returned '$rc'\n";
eval { print $socket 'foo' };
print "never reached\n";
##################


blgl at hagernas

Nov 14, 2009, 9:16 AM

Post #3 of 5 (269 views)
Permalink
Re: [perl #70487] Perl interpreter exits when calling print on a closed socket [In reply to]

Somebody never heard of SIGPIPE?


/Bo Lindbergh


ikegami at adaelis

Nov 14, 2009, 10:25 AM

Post #4 of 5 (267 views)
Permalink
Re: [perl #70487] Perl interpreter exits when calling print on a closed socket [In reply to]

On Fri, Nov 13, 2009 at 4:50 PM, kyle.getz [at] gmail (via RT) <
perlbug-followup [at] perl> wrote:

> # New Ticket Created by kyle.getz [at] gmail
> # Please include the string: [perl #70487]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=70487 >
>


> The last print statement of the script is not executed because the entire
> interpreter exits. No return code, no call to die.
>

Actually, there is a return code

$ echo $?
141

Which is SIGPIPE with a core dump. SIGPIPE is thrown by the system when
writing to a closed pipe or socket.It can be caught or ignored using

$SIG{PIPE} = 'IGNORE';

Not a bug (in Perl).


dagolden at cpan

Nov 14, 2009, 1:59 PM

Post #5 of 5 (266 views)
Permalink
Re: [perl #70487] Perl interpreter exits when calling print on a closed socket [In reply to]

On Sat, Nov 14, 2009 at 1:25 PM, Eric Brine <ikegami [at] adaelis> wrote:
> Which is SIGPIPE with a core dump. SIGPIPE is thrown by the system when
> writing to a closed pipe or socket.It can be caught or ignored using
>
>    $SIG{PIPE} = 'IGNORE';
>
> Not a bug (in Perl).

Of course!. That could probably be better documented. Not being an
IPC expert, I wouldn't have expected it except for actual pipes.
Grepping for SIGPIPE in blead's pod/ directory did reveal this in
perl581delta:

> If a socket gets closed by the server while printing to it, the client
> now gets a SIGPIPE. While this new feature was not planned, it fell
> naturally out of PerlIO changes, and is to be considered an accidental
> feature.

But almost all the other references are in relation to pipes, not
filehandles or sockets.

Maybe it could be added at least to Socket.pm or perlfunc for
'socket'. perlfunc for 'print' would be another good place to note
that printing to a closed socket or pipe will throw SIGPIPE.

-- David

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.