*BSD News Article 69036


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.vbc.net!samba.rahul.net!rahul.net!a2i!news.PBI.net!decwrl!enews.sgi.com!lll-winken.llnl.gov!uwm.edu!newsfeed.internetmci.com!in2.uu.net!yoda!ford
Newsgroups: comp.unix.bsd.misc,comp.unix.sys5.r4,comp.unix.unixware.misc,comp.protocols.tcp-ip,comp.infosystems.www.servers.unix
Followup-To: comp.unix.bsd.misc,comp.unix.sys5.r4
Message-ID: <31a1f624@yoda.omnicron.com>
Date: Tue, 21 May 1996 16:58:12 GMT
From: ford@omnicron.com (Mike "Ford" Ditto)
Organization: Omnicron Data Systems
Subject: TCP socket close() behavior (Was: Imcomplete Documents and Images from httpd)
References: <4m7r3m$9qt@nntpb.cb.att.com> <31979d8d@yoda.omnicron.com> <319900f5.21380062@news.meganet.nl> <319a205f@yoda.omnicron.com> <319b6555@yoda.omnicron.com> <4nkuav$q54@noao.edu>
Lines: 73
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:1086 comp.unix.sys5.r4:11001 comp.unix.unixware.misc:13269 comp.protocols.tcp-ip:44864 comp.infosystems.www.servers.unix:14189

I am moving this thread to comp.unix.bsd.misc and comp.unix.sys5.r4
since it has come down to a question of sockets semantics.

I submit for discussion the question of whether the kernel must attempt
to deliver pending sent data when a close() is performed on a connected
TCP socket without the SO_LINGER option enabled.

I and a few other people wrote about a problem with several httpd
packages on various SVR4 systems.  I tracked the problem down to what I
declared to be a bug in the httpd software.  Both NCSA httpd 1.5.1 and
apache 1.0.3 have this "bug".

I wrote:
> The bug is that the server does not set the SO_LINGER socket option
> before closing the socket.  This omission means that the close system
> call should discard any remaining unsent data rather than wait for the
> client to recieve and acknowledge it.  Obviously, this is undesirable
> behavior.  NCSA httpd 1.1 did it correctly -- I don't know how this bit
> of code went missing in the later versions.

rstevens@noao.edu (W. Richard Stevens) responded:
> Huh?  The *default* action of close() on a reliable socket (e.g., TCP)
> has always been that the kernel will try to send any data still in the
> socket send buffer.

No, not always.  According to "The Design and Implementation of the
4.3BSD UNIX Operating System" section 10.7:

	[... When a socket in a connected state is closed], a disconnect
	is initiated.  The socket is marked to indicate that a file
	descriptor is no longer referencing it, and the close operation
	returns successfully.  When the disconnect request completes,
	the network support notifies the socket layer, and the socket
  -->	resources are reclaimed.  The network layer may attempt to
  -->	transmit any data queued in the socket's send buffer, although
  -->	this is not guaranteed.

	Alternatively, a socket may be marked explicitly to force the
	application process to linger when closing  until pending data
	have drained and the connection has shut down [...]

The documentation for the SO_LINGER socket option (in both BSD and SVR4)
is ambiguous, but not inconsistent with the above description.

Therefore, I interpret that to strictly comply with the documented
interface, it is necessary to enable SO_LINGER before closing a socket
if you want to guarantee that the kernel will attempt to deliver all
previously written data.

> Are you saying these SVR4 stacks discarded the data in the send buffer
> when close() was called and the LINGER option was not set?  If so, I say
> the stacks are broken.

SVR4.0 and at least some versions of SVR4.2/Unixware do not attempt to
deliver unsent data in the case of a non-lingering close.

I recieved some additional information from peter@haywire.DIALix.COM
(Peter Wemm).  He says that the BSD implementation has in fact attempted
to deliver the unsent data as far back as the net/1 code, and that the
BSD Design & Implementation book is simply out of date.

But it's not clear to me that the SVR4 behavior is actually "wrong" just
because it matches the 4.3BSD spec (man pages) and not the net/1
behavior.

Is there any more authoritative documentation for this aspect of sockets
semantics?  Is the httpd software "wrong" to omit the SO_LINGER option?

					-=] Ford [=-

"But everybody wants a rock		(In Real Life:  Mike Ditto)
 to wind a piece of string around."	ford@omnicron.com
 - They Might be Giants, "We want a rock"