Mailing List Archive

sockets broken under IRIX 5.3? (fwd)
Hey porters, do you remember this problem? There's
some SGI stdio bug that I can't recall the details
of. I saw a patch for it out of SGI, but it didn't
come here to this list, so I didn't archive it. Anyone
else remember about it?

thanks,

--tom


------- Forwarded Messages

Date: Wed, 20 Dec 95 09:19:30 MST
From: Tom Christiansen <tchrist@mox>
Subject: Re: sockets broken under IRIX 5.3?
To: Matthew Black <black@engr.csulb.edu>
In-reply-to: Your message <Pine.SGI.3.91.951220081616.14526A-100000@heart.engr.csulb.edu> of
Wed, 20 Dec 95 08:16:52 PST.

hm... the pack was handcoded.

i dunno. all i know is that you shouldn't blame the book,
you shouldn't use handcoded anything, and that the perl5
Socket library i maintain has never ever had any of these
problems.

- --tom

------- Message 2

Date: Wed, 20 Dec 1995 08:27:52 -0800 (PST)
From: Matthew Black <black@engr.csulb.edu>
Subject: Re: sockets broken under IRIX 5.3?
To: Tom Christiansen <tchrist@mox.perl.com>
In-reply-to: <22774.819476370@mox>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Wed, 20 Dec 1995, Tom Christiansen wrote:
> hm... the pack was handcoded.
>
> i dunno. all i know is that you shouldn't blame the book,
> you shouldn't use handcoded anything, and that the perl5
> Socket library i maintain has never ever had any of these
> problems.

Here's my client program. It works when using syswrite() but not print.
The server and client are simply a producer and consumer. The client
accepts a line of input which is sent to the server. The server returns
a simple message counting the number of lines received and then length
of the current line.

#!/usr/local/bin/perl
use Socket;

$them = "localhost";
$port = 2345; #any port>1024 will work

# get socket values from include file
$AF_INET = AF_INET;
$SOCK_STREAM = SOCK_STREAM;
print "\$AF_INET=$AF_INET\n";
print "\$SOCK_STREAM=$SOCK_STREAM\n";

$sockaddr = 'S n C4 x8';
chop($us = `hostname`);
($name,$aliases,$proto) = getprotobyname('tcp');
($name,$aliases,$type,$len,$thisaddr) = gethostbyname($us);
($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);

$this = pack($sockaddr,$AF_INET, 0, $thisaddr);
$that = pack($sockaddr,$AF_INET, $port, $thataddr);

socket(S, $AF_INET, $SOCK_STREAM, $proto) || die "socket:$!";
bind(S, $this) || die "bind:$!";
connect(S, $that) || die "connect:$!";

# Make socket unbuffered
local($oldfh) = select(S); $| = 1; select($oldfh);

#loop on input from keyboard
while (<STDIN>) {
chop($_); # remove line terminator
$len = length($_); print "input length=$len\n";
# syswrite works...print doesn't
# syswrite (S, "$_\n",$len+1);
print S "$_\n";
$result = <S>; # get for answer from server
print "result is $result";
}

============================================================================
matthew black, network analyst | opinions expressed herein are mine and
california state university | may not reflect those of my employer
cecs department |
long beach, ca 90840 | email: black@csulb.edu
=============================(c) 1995 by Matthew Black, all rights reserved=



------- Message 3

Date: Wed, 20 Dec 95 09:51:46 MST
From: Tom Christiansen <tchrist@mox>
Subject: Re: sockets broken under IRIX 5.3?
To: Matthew Black <black@engr.csulb.edu>
In-reply-to: Your message <Pine.SGI.3.91.951220082441.14757A-100000@heart.engr.csulb.edu> of
Wed, 20 Dec 95 08:27:52 PST.

>Here's my client program. It works when using syswrite() but not print.
>The server and client are simply a producer and consumer. The client
>accepts a line of input which is sent to the server. The server returns
>a simple message counting the number of lines received and then length
>of the current line.

That's because of a bug in SGI's stdio implementation. Here's one
message demoing this. I know for certain that SGI has issued a patch
to fix it. I just don't recall what/where it is.

- ------- Forwarded Message

Date: Mon, 16 Oct 1995 00:21:54 -0400
From: Peter Whaite <peta@Athena.McRCIM.McGill.EDU>
Subject: Perl malloc bug with require >= 16376 bytes on irix5.
To: perlbug@perl.com
List-Name: perl5-porters

On our irix5.2 systems "require 'big.pl'" where 'big.pl' is of size 16376
bytes or greater corrupts memory when using perl's malloc. This manifests
itself in socket connections opened afterwards. Par (SGI's trace) revealed
either that the read syscall from the socket fd had a negative size, or that
the write syscall to the socket didnt happen (zero size?).

The problem only happened when 'big.pl' was on an SGI file system. It did not
happen on NFS sun systems. Stdio allocates different size buffers in these
two cases (16384 for the sgi fs, and 8192 for the sun fs). These sizes are
used to SvGROW in sv_gets, so it looked like SvGROW was the problem. When I
reconfigured and recompiled to use the SGI malloc library the problem went
away.

Below is a test program which shows the problem. Here is the myconfig from
the current installation which does *not* use perl's malloc, but all the other
information should be the same. Sorry I dont have the buggy one. I could
redo it if needed.

Summary of my perl5 (patchlevel 1) configuration:
Platform:
osname=irix, osver=5, archname=sgi-irix
uname='irix idefix 5.2 02282015 ip20 mips '
hint=recommended
Compiler:
cc='cc', optimize='-O', ld='ld'
cppflags='-D_POSIX_SOURCE -ansiposix -D_BSD_TYPES'
ccflags ='-D_POSIX_SOURCE -ansiposix -D_BSD_TYPES -Olimit 3000'
ldflags =''
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=1, d_casti32=define, d_castneg=undef
intsize=4, alignbytes=8, usemymalloc=n, randbits=15
Libraries:
so=so
libpth=/usr/lib /lib
libs=-lmalloc -lsun -lm -lc -lcrypt -lbsd -lPW
libc=/usr/lib/libc.so
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef
cccdlflags=' ', ccdlflags=' ', lddlflags='-shared'

Test case...

#!/local/std/bin/perl
#
# If big.pl has more than 16375 characters in it this hangs in the second
# socket read. The contents of big.pl are irrelevant. I used
#
# 1;
# __END__
# aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#
# where the 'a's were used to pad the file out to the correct size.

require 'big.pl';

# This will stop the bug by tying up the corrupted buffer.
# open(GRAB,"big.pl") || die();
# <GRAB>;

use Socket;

sub openservice
{
my($FH,$thathost,$port) = @_;
my($sockaddr,$thishost,$name,$aliased,$proto,
$type,$len,$thisaddr,$this,$thataddr,$that,$sockaddr);

$sockaddr = 'S n a4 x8';
(($name, $aliases, $proto) = getprotobyname('tcp'))
|| die;
(($name, $aliases, $port) = getservbyname($port, 'tcp'))
|| die
unless $port =~ /^\d+$/;

chop($thishost = `hostname`);
(($name, $aliases, $type, $len, $thisaddr) = gethostbyname($thishost))
|| die;
$this = pack($sockaddr, AF_INET(), 0, $thisaddr);

(($name, $aliases, $type, $len, $thataddr) = gethostbyname($thathost))
|| die;
$that = pack($sockaddr, AF_INET(), $port, $thataddr);

socket($FH, &PF_INET(), SOCK_STREAM(), $proto)
|| die;
bind($FH, $this)
|| die;
connect($FH,$that)
|| die;

select((select($FH),$| = 1)[0]);
}

openservice(ECHO,'localhost','echo');
print ECHO "Message #1\n"; # OK
print scalar <ECHO>; # OK
print ECHO "Message #2\n"; # Looks like write(2) never gets called.
print scalar <ECHO>; # Hangs (nothing to read).



- ------- End of Forwarded Message



------- Message 4

Date: Wed, 20 Dec 1995 11:41:37 -0800 (PST)
From: Matthew Black <black@engr.csulb.edu>
Subject: Re: sockets broken under IRIX 5.3?
To: Tom Christiansen <tchrist@mox.perl.com>
In-reply-to: <23361.819478306@mox>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

Tom:
Your latest response gave me an idea for rebuilding my perl5. The
perl4 that came with irix5.3 still has socket trouble. However,
It appears that they now work with perl5.001 and irix5.3. When
building perl5, I instructed perl NOT to use the malloc included with
perl.

Perhaps the default for Perl5 Configure would be to NOT use
malloc under irix. Can anyone else confirm that using SGI's malloc
solves their problem?

I'm still having trouble using the syslog facility. I'm will read
the documentation to see if it helps. I assume in perl5 that I replace
require "syslog.pl";
with
use Syslog; or use Sys::Syslog;

In your response, the quoted letter indicated a problem with sockets if
the file big.pl was size > 16K. This file doesn't exist on my system
nor under irix5.2.

On Wed, 20 Dec 1995, Tom Christiansen wrote:
> That's because of a bug in SGI's stdio implementation. Here's one
> message demoing this. I know for certain that SGI has issued a patch
> to fix it. I just don't recall what/where it is.

I'm still looking for patches too.

> ------- Forwarded Message
> Date: Mon, 16 Oct 1995 00:21:54 -0400
> From: Peter Whaite <peta@Athena.McRCIM.McGill.EDU>
> Subject: Perl malloc bug with require >= 16376 bytes on irix5.
> To: perlbug@perl.com
> List-Name: perl5-porters
>
> On our irix5.2 systems "require 'big.pl'" where 'big.pl' is of size 16376
> bytes or greater corrupts memory when using perl's malloc. This manifests
> itself in socket connections opened afterwards. Par (SGI's trace) revealed
> either that the read syscall from the socket fd had a negative size, or that
> the write syscall to the socket didnt happen (zero size?).

big.pl doesn't exist on my system nor does SGI's response center have
this file.

- --matt

============================================================================
matthew black, network analyst | opinions expressed herein are mine and
california state university | may not reflect those of my employer
cecs department |
long beach, ca 90840 | email: black@csulb.edu
=============================(c) 1995 by Matthew Black, all rights reserved=



------- Message 5

Date: Thu, 21 Dec 1995 08:32:26 -0800 (PST)
From: Matthew Black <black@engr.csulb.edu>
Subject: Re: sockets broken under IRIX 5.3?
To: Tom Christiansen <tchrist@mox.perl.com>
In-reply-to: <23361.819478306@mox>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

Tom:
Here are two netstat listings in rapid succession. My understanding of
sockets is that the system keeps a socket in the TIME_WAIT mode for a
random time (around 1 minute) after closing to prevent the address from
accidentally being reused too soon.

heart 6# netstat -na | grep 777
tcp 0 0 134.139.47.130.777 134.139.47.130.15571 ESTABLISHED
tcp 0 0 134.139.47.130.15571 134.139.47.130.777 ESTABLISHED
tcp 0 0 134.139.47.130.777 134.139.47.130.15569 TIME_WAIT
tcp 0 0 134.139.47.130.777 134.139.47.130.15554 TIME_WAIT
tcp 0 0 *.777 *.* LISTEN
tcp 0 0 *.1777 *.* LISTEN
heart 7# netstat -na | grep 777
tcp 0 0 134.139.47.130.777 134.139.47.130.15569 TIME_WAIT
tcp 0 0 134.139.47.130.777 134.139.47.130.15554 TIME_WAIT
tcp 0 0 *.777 *.* LISTEN
tcp 0 0 *.1777 *.* LISTEN

You can see that the socket at address 134.139.47.130.15571 did not remain
in the TIME_WAIT mode like the other sockets.

The only Configure option specified when building perl was to NOT use perl's
version of malloc. Sockets work better if I don't...however they still
don't work reliably. I have not installed any patches on my system because
there's no list of which are necessary. If you're aware of a fixed problem
with SGI's I/O or sockets would you please tell me.

- --matt

============================================================================
matthew black, network analyst | opinions expressed herein are mine and
california state university | may not reflect those of my employer
cecs department |
long beach, ca 90840 | email: black@csulb.edu
=============================(c) 1995 by Matthew Black, all rights reserved=



------- Message 6

Date: Thu, 21 Dec 95 09:44:00 MST
From: Tom Christiansen <tchrist@mox>
Subject: Re: sockets broken under IRIX 5.3?
To: Matthew Black <black@engr.csulb.edu>
In-reply-to: Your message <Pine.SGI.3.91.951220081616.14526A-100000@heart.engr.csulb.edu> of
Wed, 20 Dec 95 08:16:52 PST.

please send your bug to perlbug@perl.com . i don't have an SGI,
nor do i recall the exact nature of the bug nor its patch. i'm
sure they'll be able to help you better.

- --tom

------- End of Forwarded Messages
Re: sockets broken under IRIX 5.3? (fwd) [ In reply to ]
Matthew Black says:

> In your response, the quoted letter indicated a problem with sockets if
> the file big.pl was size > 16K. This file doesn't exist on my system
> nor under irix5.2.

The quoted letter was mine. Maybe I wasnt clear enough. In it I say...

> # If big.pl has more than 16375 characters in it this hangs in the second
> # socket read. The contents of big.pl are irrelevant. I used
> #
> # 1;
> # __END__
> # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> #
> # where the 'a's were used to pad the file out to the correct size.

That is you make your own big.pl. Remember this only showed up when big.pl was
on an SGI file system. If it was NFS mounted from a sun the problem didnt
occur because sgi's stdio allocated a smaller buffer.

I havent had any problems with this since I configured NOT to use the perl
malloc. That should be the default for now if others can confirm the same
behaviour on SGI systems.

I dont know about any SGI stdio patch but I havent looked either.