W3C home > Mailing lists > Public > www-talk@w3.org > May to June 1995

Lost bytes in an http server reply - very strange

From: Kee Hinckley <nazgul@utopia.com>
Date: Sun, 18 Jun 1995 20:57:33 -0400
Message-Id: <v02120d0fac0a7bd8f31b@[]>
To: www-talk@www10.w3.org
** The Problem
Sometimes large, cgi-generated html files lose blocks of data

** Background
o http1.3 server running on SunOS
o Perl cgi-script producting output
o Output in the 10-20K range

** Other details
o The browser type doesn't seem to matter, it's happened in Netscape and
Mosaic on Unix, Netscape on the Mac, my Perl htget script, and on a Mosaic
derivitive on Windows.

o It doesn't happen all the time.  I can replicate it about 2/3rds of the time.

o The loss, the times I've measured it, occurs about 11K into the file. The
beginning is there, the end is there. The amount lost is always an even multiple
lf 1K bytes.

o The log file on the server shows that the correct number of bytes were sent.

o The server loops doing freads and fwrites on a pipe. It reads in 8K
blocks. It loops the fwrite until all the bytes are written.  Only way out
of the loop is if fread returns 0 or the alarm() goes off. Both would
result in cancelling the entire stream, not just blocks in the middle.

o I saw this happen similarly a while ago using 1.3 on a Sony NEWS machine.
At the time I thought it was a Netscape bug, and I was able to alleviate,
but not entirely prevent, it by buffering output in the cgi script and then
spurting out things in 16K or so chunks.

o I strongly suspect a timing problem somewhere.  Buffering things seems to
help, and the data loss currently always seems to occur at about the place
where the script does additional database accesses.

If you want to try and see the problem, try accessing


You'll know when it fails because the output will often be screwed up and
it probably won't take you to the right entry (the <a name=EXACT> often
gets lost). That claims to be sending (and sometimes does) 18962 bytes
(assuming your using Netscape 1.1, other browsers get things in a different

Does anyone have any ideas?
At first I thought it was my scripts, but they generate the right data when
run by hand, and the server reports the right number of bytes being read.
The server counts the bytes as it reads them, not as it writes them, but I
can't see anyway for the code to fail.  (For completeness sake I've included
it below - http1.3 NCSA copyrights apply.)  The problem is client independent,
I've seen it before on my local server, so it's not our PPP software.  I've also
seen it on two different server platforms.  About the only variable that is
constent is the version of the server.

void send_fd(FILE *f, FILE *fd, void (*onexit)())
    char buf[IOBUFSIZE];
    register int n,o,w;

    exit_callback = onexit;

    while (1) {
        if((n=fread(buf,sizeof(char),IOBUFSIZE,f)) < 1) {
        if(bytes_sent != -1)
            bytes_sent += n;
        while(n) {

Kee Hinckley      Utopia Inc. - Cyberspace Architects    617/721-6100
nazgul@utopia.com                               http://www.utopia.com/

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.
Received on Sunday, 18 June 1995 20:57:37 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:57:21 UTC