From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 128921 invoked by alias); 9 Jan 2017 14:13:22 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 128913 invoked by uid 89); 9 Jan 2017 14:13:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-101.6 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=chicken, Hx-languages-length:2826, credentials, H*MI:sk:CAOTD34 X-HELO: drew.franken.de Received: from mail-n.franken.de (HELO drew.franken.de) (193.175.24.27) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jan 2017 14:13:13 +0000 Received: from aqua.hirmke.de (aquarius.franken.de [193.175.24.89]) (Authenticated sender: aquarius) by mail-n.franken.de (Postfix) with ESMTPSA id D64D6721E280D for ; Mon, 9 Jan 2017 15:13:06 +0100 (CET) Received: from calimero.vinschen.de (calimero.vinschen.de [192.168.129.6]) by aqua.hirmke.de (Postfix) with ESMTP id 340525E0898 for ; Mon, 9 Jan 2017 15:13:06 +0100 (CET) Received: by calimero.vinschen.de (Postfix, from userid 500) id 1D959A804C0; Mon, 9 Jan 2017 15:13:06 +0100 (CET) Date: Mon, 09 Jan 2017 14:13:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Hangs on connect to UNIX socket being listened on in the same process (was: Cygwin hanging in pselect) Message-ID: <20170109141306.GB843@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7iMSBzlTiPOCCT2k" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) X-SW-Source: 2017-01/txt/msg00054.txt.bz2 --7iMSBzlTiPOCCT2k Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2774 Hi Erik, On Jan 9 14:29, Erik Bray wrote: > On Mon, Jan 9, 2017 at 12:01 PM, Erik Bray wrote: > > On Fri, Jan 6, 2017 at 12:40 PM, Erik Bray wrot= e: > >> Hello, and happy new-ish year, > >> > >> I've been working on and off over the past few months on bringing > >> Python's compatibility with Cygwin up to snuff, including having all > >> pertinent tests passing. I've noticed that there are several tests > >> (which I currently skip) that cause the process to hang indefinitely, > >> and not respond to any signals from Cygwin (it can only be killed from > >> Windows). This is Cygwin 64-bit--I have not tested 32-bit. > >> [...] > > I made a little bit of progress debugging this, but now I'm stumped. > > It seems the problem is this: > > > > For each socket whose fd is passed to select() a thread_socket is > > started which calls peek_socket until there are bits ready on the Yes and no. One thread_socket is called per 62 sockets, to account for the maximum number of handles per WaitForMultipleObjects call. > > socket, or until the timeout is reached. This in turn calls > > fhandler_socket::evaluate_events. > > [...] > After playing around with this a bit more I came up with a much > simpler example. This has nothing to do with select( ) at all, > directly. Right. It has to do with how connect/accept works on AF_LOCAL sockets. The handshake doesn't work well for situations like yours, where the same thread tries to connect and accept on the same socket. This has been found a problem in porting postfix already and at the time we added a patch to circumvent the problem. Before calling connect, add this: setsockopt (sock_server, SOL_SOCKET, SO_PEERCRED, NULL, 0); setsockopt (sock_client, SOL_SOCKET, SO_PEERCRED, NULL, 0); This is, of course, a hack. The problem here is that server and client of a socket are independent of each other, and there's typically no way to know which process created the server side unless you already are connected. Chicken/egg. While replying to your mail, a thought occured to me, though. We might get away without the above setsockopt calls by adding a check to connect. It could test if the socket has already been opened by the same process and is bound. This could be accomplished by scanning the file descriptor table (dtable) of the process. If we find it, we set the above socket option on both ends and continue without the secret and credential check. Credentials could be set manually since we know user, group, and pid at this point. It's a bit of work but might be feasible. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --7iMSBzlTiPOCCT2k Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYc5pxAAoJEPU2Bp2uRE+gogoP/iK/5A2Krs/t8soVpN4SfarU 3gDRXyS3uGLhDHTaXPWMIVK2h56LNBHXK8USLNrI6I0N/po6wQlSnlBxGMA5F+J/ kWa3QvQ+GXWiI+2U/jm6uj5ftaY1KsAc8U5ElhZovnS9wm+KnneW6LJ6HpEKZT1g X6UiY8Y9/lAWtLUsMJ7jd8/nCiILTcvkuEXFUSW3PRirr3v7I8PC6Yr8k0N2BQFG dfnCKIoDunm7omK9oBFYvYHc3+qU+/0GEk8aBhpDfdaQF2sJKehxSFZ3VIzw5NZH Qjw8A296/AM42ripzASTv5vEIVfxorOIaY/aJADcDebnjCEj6VDDtWmIK0OGWNs3 hxleuM0NdR4/4HvYhD9SSdJp0BbUN12Qou4/m8rLDZ8b9ulR5YMyLXE3GAQsLebr Nk0A7GHWe3V9MXXbHzu+t0JFvMJl5aYgnT3tz01LHFW4JQBLvS9EC1jhbju+oahl WfrSH+TF8+gPNLoC+TtcTPKCP+u6aTJCT3Ea63/Zz9lbl+CjtF2IxKYy0er7vubX 1aVIUKN8Ig8X9SwuYvu8QVQmMIB3rDmTNQZ+cHouGGS6+Tlt2sGi5LrevAJToVg8 GGVHjoE3wmGAK5wGKJIi00FOQg5g/UTX0CHp7hdjBNig2verbcXjV3skiLsVtOVx /O6U2Ml+A9TkYtYIV3yk =uzLB -----END PGP SIGNATURE----- --7iMSBzlTiPOCCT2k--