From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 18 14:46:30 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 101591065692; Thu, 18 Feb 2010 14:46:30 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-bw0-f216.google.com (mail-bw0-f216.google.com [209.85.218.216]) by mx1.freebsd.org (Postfix) with ESMTP id 68DB28FC1B; Thu, 18 Feb 2010 14:46:28 +0000 (UTC) Received: by bwz8 with SMTP id 8so198174bwz.3 for ; Thu, 18 Feb 2010 06:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:to:cc:subject:references :organization:from:date:in-reply-to:message-id:user-agent :mime-version:content-type; bh=KeTsnlfQkhFI8iLMZH9bSfdnlRp583tOFVCFIVcJFEg=; b=rDilOHAnf0Hs1LYh8VtVe7HOdUzQuDEGZhNf0VlaQVsnXIuMq2X+aTkKuMqkCb83Nh 51lTDlpqzABqOAE+07QD1xJseswRzDtcNscRld8gP1yS8/UlTmePjBj3v25USZLVo7xI fND6eKqgsdr4xnIgnPJY7xc/r2MRjDZwB35HM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=to:cc:subject:references:organization:from:date:in-reply-to :message-id:user-agent:mime-version:content-type; b=cp76PqHwxxG48hoJMVJzItqvizEWM0Af1GGXkIv5sYCNcu099kC/pXdIrGPsmk3Unr AyGJJCipC1JVemBPbcillVVYg+IZYGA+X0crq3+StXMDLq3jdmdNQJOr3wTyecQ/kx3j lL/RY1tRbh5Bcxa3hdgPJH46aaQZUwsoz37SA= Received: by 10.204.24.139 with SMTP id v11mr5880892bkb.121.1266504388051; Thu, 18 Feb 2010 06:46:28 -0800 (PST) Received: from localhost (ms.singlescrowd.net [80.85.90.67]) by mx.google.com with ESMTPS id 13sm102583bwz.15.2010.02.18.06.46.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 18 Feb 2010 06:46:27 -0800 (PST) To: Robert Watson References: <86ocjn3rue.fsf@zhuzha.ua1> Organization: TOA Ukraine From: Mikolaj Golub Date: Thu, 18 Feb 2010 16:46:25 +0200 In-Reply-To: (Robert Watson's message of "Thu\, 18 Feb 2010 11\:59\:40 +0000 \(GMT\)") Message-ID: <86635ufvpa.fsf@zhuzha.ua1> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: unix socket: race on close? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2010 14:46:30 -0000 On Thu, 18 Feb 2010 11:59:40 +0000 (GMT) Robert Watson wrote: > On Thu, 18 Feb 2010, Mikolaj Golub wrote: > >> Below is a simple test code with unix sockets: the client does >> connect()/close() in loop and the server -- accept()/close(). >> >> Sometimes close() fails with 'Socket is not connected' error: > > Hi Mikolaj: > > Thanks for this report, and sorry about not spotting your earlier post > to freebsd-net. I've been fairly preoccupied the last month and not > keeping up with the mailing lists. Could I ask you to file a PR on > this, and forward me the PR number so I can claim ownership? This > should prevent it from getting lost while I catch up. kern/144061 > In short, your evaluation seems reasonable to me -- have you tried > tweaking soclose() to ignore ENOTCONN from sodisconnect() to confirm > this diagnosis fixes all the instances you've been seeing? I just have done this: 1) add logging the error when sodisconnect() returns error: --- uipc_socket.c.orig 2010-02-18 14:25:25.000000000 +0200 +++ uipc_socket.c 2010-02-18 14:55:26.000000000 +0200 @@ -120,6 +120,7 @@ __FBSDID("$FreeBSD: src/sys/kern/uipc_so #include #include #include +#include #include #include #include @@ -136,6 +137,7 @@ __FBSDID("$FreeBSD: src/sys/kern/uipc_so #include + #ifdef COMPAT_IA32 #include #include @@ -657,7 +659,7 @@ soclose(struct socket *so) if ((so->so_state & SS_ISDISCONNECTING) == 0) { error = sodisconnect(so); if (error) - goto drop; + log(LOG_INFO, "soclose: sodisconnect error: %d\n", error); } if (so->so_options & SO_LINGER) { if ((so->so_state & SS_ISDISCONNECTING) && Then on every error exit of the test application, like this a.out: parent: close error: 57 I have in the message log: Feb 18 15:35:32 zhuzha kernel: soclose: sodisconnect error: 57 2) add logging the error when sodisconnect() returns error and ignore the error: --- uipc_socket.c.orig 2010-02-18 14:25:25.000000000 +0200 +++ uipc_socket.c 2010-02-18 15:41:07.000000000 +0200 @@ -120,6 +120,7 @@ __FBSDID("$FreeBSD: src/sys/kern/uipc_so #include #include #include +#include #include #include #include @@ -136,6 +137,7 @@ __FBSDID("$FreeBSD: src/sys/kern/uipc_so #include + #ifdef COMPAT_IA32 #include #include @@ -656,8 +658,11 @@ soclose(struct socket *so) if (so->so_state & SS_ISCONNECTED) { if ((so->so_state & SS_ISDISCONNECTING) == 0) { error = sodisconnect(so); - if (error) - goto drop; + if (error) { + log(LOG_INFO, "soclose: sodisconnect error: %d\n", error); + if (error == ENOTCONN) + error = 0; + } } if (so->so_options & SO_LINGER) { if ((so->so_state & SS_ISDISCONNECTING) && After this the test application does not exits and I see in the message log: Feb 18 16:02:37 zhuzha kernel: soclose: sodisconnect error: 57 Feb 18 16:03:31 zhuzha kernel: soclose: sodisconnect error: 57 Feb 18 16:05:49 zhuzha last message repeated 4 times Feb 18 16:15:50 zhuzha last message repeated 13 times -- Mikolaj Golub