From owner-freebsd-hackers Sun Nov 8 15:37:45 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA07382 for freebsd-hackers-outgoing; Sun, 8 Nov 1998 15:37:45 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from awfulhak.org (awfulhak.force9.co.uk [195.166.136.63]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA07097 for ; Sun, 8 Nov 1998 15:35:09 -0800 (PST) (envelope-from brian@Awfulhak.org) Received: from woof.lan.awfulhak.org (root@woof.lan.Awfulhak.org [172.16.0.7]) by awfulhak.org (8.8.8/8.8.8) with ESMTP id XAA10008; Sun, 8 Nov 1998 23:33:21 GMT (envelope-from brian@Awfulhak.org) Received: from woof.lan.awfulhak.org (brian@localhost [127.0.0.1]) by woof.lan.awfulhak.org (8.9.1/8.9.1) with ESMTP id XAA06518; Sun, 8 Nov 1998 23:34:35 GMT (envelope-from brian@woof.lan.awfulhak.org) Message-Id: <199811082334.XAA06518@woof.lan.awfulhak.org> X-Mailer: exmh version 2.0.2 2/24/98 To: Marc Slemko cc: Brian Somers , freebsd-hackers@FreeBSD.ORG Subject: Re: bind()/listen() race In-reply-to: Your message of "Sun, 08 Nov 1998 11:37:37 PST." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 08 Nov 1998 23:34:34 +0000 From: Brian Somers Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > On Sun, 8 Nov 1998, Brian Somers wrote: > > > If I create a local domain socket with bind(), there's a period > > between that and the listen() where a connect() will fail. Is there > > any way to circumvent the problem ? > > Why is it a problem to have connects fail before you listen() but not a > problem to have them fail before you bind()? > > I'm not sure I see the race condition. Once you listen(), you can accept > connections. Before you listen(), you can't. The code says something like: if (bind(blah) < 0) { /* we're happy to be the client */ if (connect(blah) < 0) { socket is bound without a listen ! } } else if (listen(blah) < 0) { oops ! } The sockaddrs are local domain sockets used by ppp in multilink mode. Whoever gets to be the server will survive. The other ppp will become the client, pass a file descriptor to the server and hang around holding the session 'till the other ppp kills it. However, if the two ppps get unlucky, one bind()s and the second fails then tries to connect() and fails 'cos the server hasn't listen()ed yet. This is bad news. The only way I can see around it - given that I can't sleep() in ppp without screwing up with other timing issues - is to detect the error and do a 1 second timeout, and try again then. This is a nasty thing to have to do.... I'd prefer an atomic bind()/listen() facility.... Hence the question :-) -- Brian , , Don't _EVER_ lose your sense of humour.... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message