delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:date:from:to:subject:message-id:reply-to | |
:references:mime-version:content-type:in-reply-to; q=dns; s= | |
default; b=XsYw1QHs3zhulNjFCcPNHnH2wSDc+AdMrWU0fFUDd6C4KOFFkoEc+ | |
JvxfLMDF91Nbl90NN+iEOVS6E6xrlZSN9n5wRIMMn5tm0wXr+VixJ0EIWil9exY6 | |
3ghTXDXbGRflUgzGRpTc7VCQm0dqJol1LZ72SYIVC94pt0qd6eXvGI= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:date:from:to:subject:message-id:reply-to | |
:references:mime-version:content-type:in-reply-to; s=default; | |
bh=RUD3hVbxne7JHDGWtEKjnQXOhvc=; b=FA21sB6hW+z+kSz4/a+zoto2bPlf | |
f0VkUfzush/rQjAqWEkHuCh62iDwyCFUVd5pl0g4DKbngywciu7OLARPa/CwWafj | |
CphPez+xOVnGG+yATlHWC/QXE08pPnYNybRbnX00c2lI6lJhAaiCgYKpdGeF3OTF | |
ISRNDh9bL93WJFs= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Virus-Found: | No |
X-Spam-SWARE-Status: | No, score=-101.8 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sake |
X-HELO: | drew.franken.de |
Date: | Tue, 16 Jan 2018 16:42:34 +0100 |
From: | Corinna Vinschen <corinna-cygwin AT cygwin DOT com> |
To: | cygwin AT cygwin DOT com |
Subject: | Re: Cygwin socket option SO_REUSEADDR operates unlike Linux |
Message-ID: | <20180116154234.GB3255@calimero.vinschen.de> |
Reply-To: | cygwin AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
References: | <Pine DOT BSF DOT 4 DOT 63 DOT 1801122348420 DOT 62607 AT m0 DOT truegem DOT net> <20180113135127 DOT GA22225 AT calimero DOT vinschen DOT de> <e072e320-fca4-582d-508e-91c5c0d78bc6 AT maxrnd DOT com> <20180115200249 DOT GA3009 AT calimero DOT vinschen DOT de> |
MIME-Version: | 1.0 |
In-Reply-To: | <20180115200249.GA3009@calimero.vinschen.de> |
User-Agent: | Mutt/1.9.1 (2017-09-22) |
--Y7xTucakfITjPcLV Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Jan 15 21:02, Corinna Vinschen wrote: > On Jan 13 13:39, Mark Geisert wrote: > > Corinna Vinschen wrote: > > > On Jan 13 00:36, Mark Geisert wrote: > > > > ~ ./bindtest > > > > 1st socket is 3 > > > > 1st bind OK > > > > 1st connect OK > > > > 2nd socket is 3 > > > > 2nd bind OK > > > > 2nd connect: Address already in use > > > >=20 > > > > ~ ./bindtest > > > > 1st socket is 3 > > > > 1st bind OK > > > > 1st connect: Address already in use > > > >=20 > > > > On Fedora 27, running the same STC shows: > > > >=20 > > > > [mark AT lux ~]$ netstat -an|grep :111 > > > > tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN > > > > tcp6 0 0 :::111 :::* LISTEN > > > > udp 0 0 0.0.0.0:111 0.0.0.0:* > > > > udp6 0 0 :::111 :::* > > > > [mark AT lux ~]$ ./bindtest > > > > 1st socket is 3 > > > > 1st bind OK > > > > 1st connect OK > > > > 2nd socket is 3 > > > > 2nd bind OK > > > > 2nd connect OK > > >=20 > > > I can't reproduce this: > > >=20 > > > $ uname -sr > > > Linux 4.14.13-300.fc27.x86_64 > > > $ netstat -an|grep :111 > > > tcp 0 0 0.0.0.0:111 0.0.0.0:* L= ISTEN > > > tcp6 0 0 :::111 :::* L= ISTEN > > > udp 0 0 0.0.0.0:111 0.0.0.0:* > > > udp6 0 0 :::111 :::* > > > $ ./bindtest > > > 1st socket is 3 > > > 1st bind OK > > > 1st connect OK > > > 2nd socket is 3 > > > 2nd bind OK > > > 2nd connect: Cannot assign requested address > > > [...] > > Rats. I'll have to investigate a couple of directions, deeper. It mak= es > > sense that connect() returns EADDRINUSE rather than bind() [...] >=20 > After some more digging it turns out that both of the above observations > on Linux are correct. I can reproduce the 2nd connect succeeding by > simply adding a `sleep(1)' after the first close. So it turns out that > Linux has a timing issue at socket cleanup which can be alleviated > by an extra sleep. I opened a case about this issue. EADDRNOTAVAIL > sounds a bit weird in this scenario, but it's kind of ok. >=20 > In terms of Cygwin, the EADDRINUSE is a completely different matter. >=20 > It turns out that the second connect fails because the first socket > connection is in TIME_WAIT state. This is not exactly correct in POSIX > terms. The TIME_WAIT connection should not disallow a new socket to > reuse the same local address. That's what we observe on Linux (apart from > the timing issue). >=20 > But here's the problem: Regardless if we actually use SO_REUSEADDR or > not, Windows sockets apparently disallows a subsequent connect to > succeed while the first socket is still in TIME_WAIT. I tweaked Cygwin > to enforce SO_REUSEADDR before bind, but connect still fails with > EADDRINUSE as long as the first socket is in TIME_WAIT. >=20 > It seems the code path for listen/accept is different here compared to > connect. Given that SO_REUSEADDR seems to cover mostly server side > scenarios, and given that I don't see this scenario discussed at all > in Steven's book, I wonder if bind/connect is a bit of a grey area. >=20 > Either way, the bottom line is that this is a WinSock restriction, > apparently. As of today, I don't see any way around that. For completeness sake I converted your testcase into a WinSock-only executable, built with Mingw-w64, and the problem persists, on Windows7 as well as on Windows 10. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --Y7xTucakfITjPcLV Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlpeHWkACgkQ9TYGna5E T6DcYQ//aiStYxTU2QokFZYhcBs3n5VUScm51QUdb7hIqW3DPKjuh0tl09T95PC+ aVCxxZiH10oXIsRK4hwjM0p7tTqIkd4rYqWhbWAjF7c3BBSU4u11ILkBxmYfb/Zc tXlPuIWE0adQFNNV8oh0ldieJJBQMibqJTRsJl47nBAry/qSIoZUQRUihSBDlnFD A55I4muRiTpDDmaNaOijEqW65fqA8BeFsh6pUMy+RJkN2jaEXWc9D0+14Xl7mSfv u6lSYFvEBsvOjq+0RI3/SSP2ihTPey2Xt10GMG2kAaurIcl8GqSlv1gNRX4QHkoM WlerIH2JzHtkf3OPg1kvj5MZU8gBia+/ckGpI+NEJstcSkCP2ZMDvEIvpdrRkLxZ 4Ws2Ye1rKMKTUjJGu+UXphgwcRsOKVkxuQRFOuDJcflcAz3zjH0eGHgTQNZLG+do Ca6sfEmYT+44eFzczYg0NAypC4zc38JI/Ud0ulxcabQHt5cGOKuZYgtQocYTY9KY ciec7Y5MtEv2gRLRmi/10YijULLCGYIg/6BkNzjk25pfXl6tJMw+ebTFLXj/GG9Q FOuElTGp72looq5DZaAM61XKcK06AvYODxyPSpN8g+xnWpwH35qshDRriB7nfRIW C5k8HhF8IcCOt0TK5/yboB1/FUZz9QDWFplf97cckdJHmX1TjMY= =LQ8a -----END PGP SIGNATURE----- --Y7xTucakfITjPcLV--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |