From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBepx-0002K5-Ua for qemu-devel@nongnu.org; Mon, 06 Nov 2017 05:41:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBepu-0006Uh-T7 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 05:41:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41778) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBepu-0006Sx-ND for qemu-devel@nongnu.org; Mon, 06 Nov 2017 05:40:58 -0500 Date: Mon, 6 Nov 2017 10:40:53 +0000 From: "Daniel P. Berrange" Message-ID: <20171106104053.GD23361@redhat.com> Reply-To: "Daniel P. Berrange" References: <20171016201650.18399-1-berrange@redhat.com> <20171016201650.18399-4-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PULL v1 03/11] sockets: Handle race condition between binds to the same port List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Developers , Knut Omang On Fri, Nov 03, 2017 at 06:54:44PM +0000, Peter Maydell wrote: > On 16 October 2017 at 21:16, Daniel P. Berrange wrote: > > From: Knut Omang > > > > If an offset of ports is specified to the inet_listen_saddr function(), > > and two or more processes tries to bind from these ports at the same time, > > occasionally more than one process may be able to bind to the same > > port. The condition is detected by listen() but too late to avoid a failure. > > > > This function is called by socket_listen() and used > > by all socket listening code in QEMU, so all cases where any form of dynamic > > port selection is used should be subject to this issue. > > > > Add code to close and re-establish the socket when this > > condition is observed, hiding the race condition from the user. > > > > Also clean up some issues with error handling to allow more > > accurate reporting of the cause of an error. > > > > This has been developed and tested by means of the > > test-listen unit test in the previous commit. > > Enable the test for make check now that it passes. > > > > Reviewed-by: Bhavesh Davda > > Reviewed-by: Yuval Shaia > > Reviewed-by: Girish Moodalbail > > Signed-off-by: Knut Omang > > Reviewed-by: Daniel P. Berrange > > Signed-off-by: Daniel P. Berrange > > Hi. Coverity points out that this code could leak a socket fd > (CID 1381805): Yeah, I have a patch posted a week or two back to fix this. I'll get a pull request in before release to fix it, along with test suite Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|