From owner-freebsd-hackers@FreeBSD.ORG Sat Dec 8 21:49:45 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9ACE9882 for ; Sat, 8 Dec 2012 21:49:45 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by mx1.freebsd.org (Postfix) with ESMTP id 2538F8FC08 for ; Sat, 8 Dec 2012 21:49:44 +0000 (UTC) Received: by mail-wi0-f170.google.com with SMTP id hq7so383123wib.1 for ; Sat, 08 Dec 2012 13:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=W4DY7KtSrPC1O3GdPM0qv5efgyEhI7D47Ne1NQipOTY=; b=EccgYqPSffzyq057Ts9ZCqwjWnX0bnHuX2HDMW6u/9jI7zBlS6ip9QiUv8NrLKue5a nQOWiIW5oCQxwhuojKw/2Vaz95H6s+bnIaa2wmG3kIWaIls6YeqgHAN0rDyh5FZbn8c6 hfKZltzHDs2BzHORbPv2t6WCqlLY2UJtlGxUhFQKTik4odbMpWmrrPZ1UBc6y8MgHKdM JznN+Cr9UfJYH3zTADidyJglQcMt1/MLlgOrT1G3qbbuIUTkn3eQ7/2mcM8iAV8yAblz ATzCc3WgBrC2Si7D6irUJYo5JoS60W9UUHS6mVIZgJak1PHUBhNMubpS0h5R9d1bWg/X 9fdg== MIME-Version: 1.0 Received: by 10.216.85.211 with SMTP id u61mr3814531wee.212.1355003378348; Sat, 08 Dec 2012 13:49:38 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.217.57.9 with HTTP; Sat, 8 Dec 2012 13:49:38 -0800 (PST) In-Reply-To: <1354990425.6752.10.camel@localhost.localdomain> References: <1354990425.6752.10.camel@localhost.localdomain> Date: Sat, 8 Dec 2012 13:49:38 -0800 X-Google-Sender-Auth: HEZZqdXgYrPAfP7BEKXgmUMNar4 Message-ID: Subject: Re: Possible obscure socket leak when system under load and listener is slow to accept From: Adrian Chadd To: Richard Sharpe Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Dec 2012 21:49:45 -0000 Hi, If this is a real leak, please file a PR so it doesn't get lost. *cough* let me rephrase that - so the eager PR beavers can keep chasing it iup. But, wow. Nice catch! Adrian On 8 December 2012 10:13, Richard Sharpe wrote: > Hi folks, > > Our QA group (at xxx) using Samba and smbtorture has been seeing a > lot of cases where accept returns ECONNABORTED because the system load > is high and Samba has a large listen backlog. > > Every now and then we get a crash in smbd or in winbindd and winbindd > complains of too many open files in the system. > > In looking at kern_accept, it seems to me that FreeBSD can leak a socket > when kern_accept calls soaccept on it but gets ECONNABORTED. This error > is the only error returned from tcp_usr_accept. > > It seems like the socket taken off so_comp is never freed in this case > and that there has been a call on soref on it as well, so that something > like the following is needed in the error path: > > ==== //some-path/freebsd/sys/kern/uipc_syscalls.c#1 > - /home/rsharpe/dev-src/packages/freebsd/sys/kern/uipc_syscalls.c ==== > @@ -433,6 +433,14 @@ > */ > if (name) > *namelen = 0; > + /* > + * We need to close the socket we unlinked > + * so we do not leak it. > + */ > + ACCEPT_LOCK(); > + SOCK_LOCK(so); > + soclose(so); > goto noconnection; > } > if (sa == NULL) { > > I think an soclose is needed at this point because soisconnected has > been called on the socket. > > Do you think this analysis is reasonable? > > We are using FreeBSD 8.0 but it seems the same is true for 9.0. However, > maybe I am wrong since I am not sure if the fdclose call would free the > socket, but a quick look suggested that it doesn't. > > I would appreciate your feedback. > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"