From owner-freebsd-questions@FreeBSD.ORG Thu Apr 21 20:03:41 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C559516A4CE for ; Thu, 21 Apr 2005 20:03:41 +0000 (GMT) Received: from zhonka1.zhonka.net (zhonka1.zhonka.net [66.228.195.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6E13743D41 for ; Thu, 21 Apr 2005 20:03:41 +0000 (GMT) (envelope-from freebsd@philip.pjkh.com) Received: from wolf.pjkh.com ([66.228.196.74]) by zhonka1.zhonka.net (Post.Office MTA v3.5.3 release 223 ID# 0-58414U4500L450S0V35) with ESMTP id net; Thu, 21 Apr 2005 13:03:40 -0700 Received: from localhost (localhost [127.0.0.1]) by wolf.pjkh.com (Postfix) with ESMTP id 124AA5822; Thu, 21 Apr 2005 13:03:35 -0700 (PDT) Received: from wolf.pjkh.com ([127.0.0.1]) by localhost (wolf.pjkh.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 86313-05; Thu, 21 Apr 2005 13:03:34 -0700 (PDT) Received: by wolf.pjkh.com (Postfix, from userid 1000) id D1D565827; Thu, 21 Apr 2005 13:03:34 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by wolf.pjkh.com (Postfix) with ESMTP id CCEED5826; Thu, 21 Apr 2005 13:03:34 -0700 (PDT) Date: Thu, 21 Apr 2005 13:03:34 -0700 (PDT) From: Philip Hallstrom To: LukeD@pobox.com In-Reply-To: <20050421123644.U6491@border.crystalsphere.multiverse> Message-ID: <20050421130012.V86918@wolf.pjkh.com> References: <20050421123644.U6491@border.crystalsphere.multiverse> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at pjkh.com cc: freebsd-questions@freebsd.org Subject: Re: Reusing a port after a crash X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2005 20:03:41 -0000 >> From time to time, my torrent filesharing application will crash or need > to be killed. The application is configured to listen on a specific port. If > I try to restart the application after improper termination, I receive a > fatal error message stating that the port is already in use. > > Before restarting the application, I verify that the application did indeed > shut down (via 'ps -aux') and 'sockstat -l' shows that no application is > using the port in question, so I don't understand how the port could still be > 'in use'. > > The only way I've found to restart the application after improper termination > is to reboot the whole system. Is there something else I could try? Does > this kind of thing tend to happen to network applications when they crash or > could this be specific to my application? What little tinkering I've done in the socket world reminds me of this: -------------------------------------------------------------- % man setsockopt ... SO_REUSEADDR enables local address reuse SO_REUSEPORT enables duplicate address and port bindings ... SO_REUSEADDR indicates that the rules used in validating addresses sup- plied in a bind(2) call should allow reuse of local addresses. SO_REUSEPORT allows completely duplicate bindings by multiple processes if they all set SO_REUSEPORT before binding the port. This option per- mits multiple instances of a program to each receive UDP/IP multicast or broadcast datagrams destined for the bound port. -------------------------------------------------------------- Basically, what I remember about this is that if you supply those options when creating the socket and your app crashes, you can start it back up using the same host:port otherwise you get the message you're getting... I'm sure a good networking would be able to explain it better...