From owner-freebsd-current@FreeBSD.ORG Fri Nov 25 05:44:16 2005 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0FFE716A41F; Fri, 25 Nov 2005 05:44:16 +0000 (GMT) (envelope-from mayank@microsoft.com) Received: from mail-sin2.microsoft.com (mail-sin2.microsoft.com [207.46.50.82]) by mx1.FreeBSD.org (Postfix) with ESMTP id 214D743D5C; Fri, 25 Nov 2005 05:44:14 +0000 (GMT) (envelope-from mayank@microsoft.com) Received: from APS-MSG-01.southpacific.corp.microsoft.com ([157.60.218.52]) by mail-sin2.microsoft.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 25 Nov 2005 13:44:14 +0800 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Fri, 25 Nov 2005 13:44:13 +0800 Message-ID: <3A5384BC2FBA4C488865F2275A036BFF040B285D@APS-MSG-01.southpacific.corp.microsoft.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: What is the correct behaviour for local socket(AF_UNIX) in the following scenario? thread-index: AcXxVno/bOuphiUIQ4S9gX6juQAODQAK+1FQ From: "Mayank Kumar" To: "Robert Watson" X-OriginalArrivalTime: 25 Nov 2005 05:44:14.0195 (UTC) FILETIME=[447C8C30:01C5F183] Cc: freebsd-current@freebsd.org Subject: RE: What is the correct behaviour for local socket(AF_UNIX) in the following scenario? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Nov 2005 05:44:16 -0000 Hi Robert >From this I understand that if p1 closes the socket, then all the data written by it is discarded since the buffers associated with this socket no longer exists. If that is the case, then this is not at all true that p1 can write data on a socket and close it and exit=20 and p2 will still be able to retrieve the data written by p1. Does FreeBSD differ with solaris or other unixes in this implementation. I believe that Solaris does support the above scenario although I am not sure. Do you know How other unixes behave here. Because it makes a lot=20 of sense for localsockets to facilitate IPC on a system by supporting the above scenario between two processes. Regards Mayank -----Original Message----- From: Robert Watson [mailto:rwatson@FreeBSD.org]=20 Sent: Friday, November 25, 2005 5:54 AM To: Mayank Kumar Cc: freebsd-current@freebsd.org Subject: Re: What is the correct behaviour for local socket(AF_UNIX) in the following scenario? On Fri, 25 Nov 2005, Mayank Kumar wrote: > I am trying to understand the behavior of localsockets in the=20 > following scenario. > > A process p1 writes a huge amoount of data to a AF_UNIX,DGRAM socket=20 > and exits. Now if there is no process p2 to read the data written by=20 > process > p1 from the same localsocket, then this has resulted in a huge memory=20 > leak on a FreeBSD system. > > I want to understand, if there is a mechanism in FreeBsd to take care=20 > of this leak or this is the expected behaviour and application writers > should take care of this situation. Also what should be the behaviour=20 > on such a socket if shutdown or close is issued on such a socket. Any=20 > help on the behaviour on other unixes in the same scenario would also=20 > help a lot. Mayank, The key to understanding how this is handled is to understand that UNIX domain sockets aren't file system objects -- the file system simply provides a name space by which to reach the socket. The buffers associated with UNIX domain sockets belong to the sockets, not to the name. You can think of this in the same way as you might think of port numbers and IP addresses, although there are some subtle differences. There are two common operational modes for UNIX domain sockets: stream mode, and datagram mode. In stream mode, a listen socket is bound to the name, and then new socket pairs are generated when that name is connected.=20 In datagram mode, a single socket exists on the "server" end, and then a series of other sockets may send to it using sendto and send. The buffers are associated with the active communication sockets in both case, so if all endpoints are closed, the name persists, but has no persisting buffers. So a name can be leaked (i.e., not be unlinked when a process is done with it), which is similar to leaking a temporary file that isn't unlinked. Hope this helps, Robert N M Watson