From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 08DC6385E000 for ; Thu, 6 May 2021 12:18:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 08DC6385E000 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marco.atzeri@gmail.com Received: by mail-ej1-x62b.google.com with SMTP id a4so7971532ejk.1 for ; Thu, 06 May 2021 05:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=Fd0+Jqu2hhKMC4XcB7/rJwalOoVGgTcqbSORXsX5KUA=; b=Bz2a7v7gltcm2wZMMOqTG3VKPn+e5z06uyed6EH+wk+S84tiOqpLJyj/ZnvS0WItTk mdTGAzWKzlyyNJt43GnLWPQyNkCENQeDaIcDbusdY1rB6S0fnVeO7PIjorI5tPFG20ew ix0oTtuam/Ighko3IgZiEM0MzOb6MhdUrTHoWpliEziTpZqTPPG/LfNEz6Y8OUmNdIPw CNUr6BoLY3ZxG4o/77xLnBCNEFFbZecPsnBUvVBUKTNBCUkwFid3zRB5B0K8HyJKHtHT jaHk+fn4s4ZW8nAhaerwSATHTIlHJhW50Hep60uaTvtahtcpp5eh5+PmD5Fmw/Dd4tyV yIPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Fd0+Jqu2hhKMC4XcB7/rJwalOoVGgTcqbSORXsX5KUA=; b=FWIjaEPZs+Pz2/jjdAt0tuV1Wf+zkdkDCCzKkpmLn7oQ/0v4pkr5wywfBgYHkYrcHA OXTzwf4eRbWi+GUqAIaZyUKS6pK+iE5/m6DViTfs35l6sgQ1R3VJM4hskuD/IsnaCjK0 PMuCDkNWcGE2lybVBIjYFSC3vK6MLydM91U2ssWghUg7vJ2r1OfGYKEgcqHdcjE89K0q x56gbkZK/1DqBszZZGvVIImfw51a22ARp0TTQIdGClU5W4/V5x5u7HZy1PxYOvXdKAsV nKWICgoYQFagLPa8Ff1sBCYucGCTk8fRGBzkZqB7tklBMBPz6OeFONzMDXySa24xstBl hGrg== X-Gm-Message-State: AOAM5312Ulb9c5JCE5RgqV83k+VFHc2DyemTHyttBex88OLWLh4GP4Cp /Qo3mHOGsyKRN9YDzQEwv3rlYAt9Z49UAA== X-Google-Smtp-Source: ABdhPJyLY9oHcxXvw2gvchzNwMlpIDrCNaxfcFLdOvIdyxPreOJ1IX9uAXTYBrcUave/b0RODd9JMA== X-Received: by 2002:a17:906:87cc:: with SMTP id zb12mr4211252ejb.138.1620303501002; Thu, 06 May 2021 05:18:21 -0700 (PDT) Received: from ?IPv6:2003:cc:9f04:e3ba:b17e:2a44:1956:1471? (p200300cc9f04e3bab17e2a4419561471.dip0.t-ipconnect.de. [2003:cc:9f04:e3ba:b17e:2a44:1956:1471]) by smtp.gmail.com with ESMTPSA id j16sm1540155edr.9.2021.05.06.05.18.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 May 2021 05:18:20 -0700 (PDT) Subject: Re: python > 3.5: Issue with unix domain sockets To: cygwin-developers@cygwin.com References: <1620046759893.5340@bmw.de> <2cde4128-6a3d-7431-6608-a2184d23964a@cornell.edu> <134fa003-836f-1184-79eb-e31dfd852a64@maxrnd.com> <50e76a43-48a1-f655-674a-1b4865dc62cf@maxrnd.com> From: Marco Atzeri Message-ID: <792749ef-7bb0-a7b0-b508-5192c0027023@gmail.com> Date: Thu, 6 May 2021 14:18:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: it Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2021 12:18:23 -0000 On 06.05.2021 12:30, Corinna Vinschen wrote: > On May 6 02:24, Mark Geisert wrote: >> Corinna Vinschen wrote: >>> On May 4 22:04, Mark Geisert wrote: >>>> Corinna Vinschen wrote: >>>>> On May 4 02:45, Mark Geisert wrote: >>>>>> [blah blah...] >>>>> You're supposed to call the special setsockopt(SO_PEERCRED) on the >>>>> accepting socket. The no_getpeereid property is inherited by the >>>>> accepted socket. >>>> >>>> Ah, of course. Well, I couldn't figure out a way to do the setsockopt() >>>> call some times but not others, because Python can't reach into the Cygwin >>>> DLL. Nor should it. >>>> >>>> Since this Python patch is supposed to be a temporary workaround, I took the >>>> tack that it should just ignore an error return from >>>> setsockopt(SO_PEERCRED). In this fashion the handshake will be turned off >>>> when it can be, and when it can't (on the accepted socket) the attempt will >>>> error but that error will be ignored. >>> >>> Sorry Mark, but I don't understand how you concluded that ignoring the >>> error from setsockopt(SO_PEERCRED) is the solution I pointed out above. >>> >>> The right thing to do is to call setsockopt(SO_PEERCRED) (and check its >>> return value) before calling listen() on the accepting socket. The >>> no_getpeereid property gets propagated to the accepted sockets and thus >>> there's no need to call it again for these sockets. >> >> The strategy requires more precise language than I used, sorry. I do >> understand what you're saying most recently, and have since my "of course" >> statement. >> >> Inside the Python runtime environment, I only get visibility to the socket >> Cygwin has provided at one point, which is where Python inits its own >> context for that socket. I can't tell whether the socket is the result of a >> socket() call or from an accept() call. I can't even tell whether it's >> connected. I can tell that it's AF_UNIX and can tell whether it's >> SOCK_DGRAM or SOCK_STREAM. > > Ah, ok. Sounds like a shitty interface to me, but if that's what you > have to work with... > >> So in this constrained situation, I decided to just call >> setsockopt(SO_PEERCRED) and ignore any errors. (Case 1:) If it doesn't >> error, the socket came from socket() and now has the peer handshake turned >> off. (Case 2:) If it does error, the socket came from accept(), i.e. it's >> an accepted socket, and though we couldn't turn off handshake here, it's >> already turned off due to inheritance from the accepting socket. The >> accepting socket has it turned off already because it was earlier Case 1 >> (i.e. both ends of the connection get treated, as long as they are both >> Python apps). >> >> I know that in general it's poor practice to ignore errors but given the >> constraints here and that the possible cases are (I believe) well known, >> this is a solution that works to solve the most recent issue and the >> original issue. Now that I think about it, the patch could be tightened up >> by only ignoring EALREADY rather than ignoring all errors. Would you be >> okay with that? > > Sounds good to me. > > Thanks for explaining the situation! > > > Corinna > as general info with the current implementation all the tests on /usr/lib/python3.8/test/test_asyncio pass except one. It is a huge improvement versus previous python packages $ mv test_subprocess.py test_subprocess.py-bk $ pytest .... Results (102.08s): 1939 passed 31 skipped test_subprocess.py is still frozing .......................................................................Traceback (most recent call last): File "test_subprocess.py-bk", line 725, in unittest.main() File "/usr/lib/python3.8/unittest/main.py", line 101, in __init__ self.runTests() File "/usr/lib/python3.8/unittest/main.py", line 271, in runTests self.result = testRunner.run(self.test) File "/usr/lib/python3.8/unittest/runner.py", line 176, in run test(result) File "/usr/lib/python3.8/unittest/suite.py", line 84, in __call__ return self.run(*args, **kwds) File "/usr/lib/python3.8/unittest/suite.py", line 122, in run test(result) File "/usr/lib/python3.8/unittest/suite.py", line 84, in __call__ return self.run(*args, **kwds) File "/usr/lib/python3.8/unittest/suite.py", line 122, in run test(result) File "/usr/lib/python3.8/unittest/case.py", line 736, in __call__ return self.run(*args, **kwds) File "/usr/lib/python3.8/unittest/case.py", line 676, in run self._callTestMethod(testMethod) File "/usr/lib/python3.8/unittest/case.py", line 633, in _callTestMethod method() File "test_subprocess.py-bk", line 175, in test_kill returncode = self.loop.run_until_complete(proc.wait()) File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete self.run_forever() File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever self._run_once() File "/usr/lib/python3.8/asyncio/base_events.py", line 1823, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.8/selectors.py", line 415, in select fd_event_list = self._selector.poll(timeout) KeyboardInterrupt Regards Marco