From owner-freebsd-arch@FreeBSD.ORG Fri Dec 22 02:18:15 2006 Return-Path: X-Original-To: freebsd-arch@FreeBSD.org Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8AB3D16A40F; Fri, 22 Dec 2006 02:18:15 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (gate.funkthat.com [69.17.45.168]) by mx1.freebsd.org (Postfix) with ESMTP id 36F8F13C458; Fri, 22 Dec 2006 02:18:15 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (ohaeya3em79mpkgl@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.6/8.13.3) with ESMTP id kBM211Yg031508; Thu, 21 Dec 2006 18:01:01 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.6/8.13.3/Submit) id kBM211Ml031507; Thu, 21 Dec 2006 18:01:01 -0800 (PST) (envelope-from jmg) Date: Thu, 21 Dec 2006 18:01:01 -0800 From: John-Mark Gurney To: Robert Watson Message-ID: <20061222020101.GC4982@funkthat.com> Mail-Followup-To: Robert Watson , Julian Elischer , Daniel Eischen , David Xu , freebsd-arch@freebsd.org References: <32874.1165905843@critter.freebsd.dk> <20061220153126.G85384@fledge.watson.org> <200612210820.09955.davidxu@freebsd.org> <4589E7D2.9010608@ironport.com> <20061221152115.U83974@fledge.watson.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20061221152115.U83974@fledge.watson.org> User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 5.4-RELEASE-p6 i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html Cc: Daniel Eischen , Julian Elischer , David Xu , freebsd-arch@FreeBSD.org Subject: Re: close() of active socket does not work on FreeBSD 6 X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Dec 2006 02:18:15 -0000 Robert Watson wrote this message on Thu, Dec 21, 2006 at 15:22 +0000: > >I think you are only intersted in treads that are sleeping.. so you allow > >a sleeping thread to save a pointer to the fd (or whatever) on which it is > >sleeping, along with the sleep address. > > > >items that are not sleeping are either already returning, or are going to > >sleep, in which case they can check at that time. > > Hence my question about select and poll: should they throw an exception > state when a file descriptor is closed out from under them? They often > sleep on hundreds or thousands of file descriptors, and not just one. IMO, your program is buggy if you close the file descriptor before everything is out of the kernel wrt the fd... It means that your close statement isn't waiting for things to be cleanly shut down, and that you still have dangling reference counts to the parts of the code that is in the kernel... I used to expect something similar w/ an kqueue based event driven web server, and found that I had bugs due to assuming that I could close it whenever I want... What happens if you close the fd between the time select returns and you process it? What happens if the fd gets closed, and another thread (or an earlier fd that accepts connections) reuses that fd? And then youre state machine isn't read to get an event since it isn't suppose to get one yet... The kernel isn't buggy wrt closing a fd when another thread is using it, it's the program that's buggy... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."