From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.187]) by sourceware.org (Postfix) with ESMTPS id EAACD395B839 for ; Tue, 4 May 2021 12:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EAACD395B839 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=cygwin.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=corinna-cygwin@cygwin.com Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MIdNt-1lj4Z01spB-00EhnZ for ; Tue, 04 May 2021 14:27:51 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id DDA4FA80D9A; Tue, 4 May 2021 14:27:50 +0200 (CEST) Date: Tue, 4 May 2021 14:27:50 +0200 From: Corinna Vinschen To: cygwin-developers@cygwin.com Subject: Re: python > 3.5: Issue with unix domain sockets Message-ID: Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: cygwin-developers@cygwin.com References: <1620046759893.5340@bmw.de> <2cde4128-6a3d-7431-6608-a2184d23964a@cornell.edu> <134fa003-836f-1184-79eb-e31dfd852a64@maxrnd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <134fa003-836f-1184-79eb-e31dfd852a64@maxrnd.com> X-Provags-ID: V03:K1:fJ9lNih9ASrH8eBYZ02vIIE7l6YdxG8My6BMbaD3wMGfwxEdT48 u1lGt5hJRxf9fiQW52Wxd/hZMDgc61vtHybI3X38DnJdSzli4MkMdaldk3ToGXezqt13bsT qQk4Ah8OLcPVmD/FaZDu++CV+Bqdr/ngWDbKXuOGX7G4EH6wUoZKF0Hfb67efVsR082CPgZ qtoKrORA01SwmKBJE/I4A== X-UI-Out-Filterresults: notjunk:1;V03:K0:2MqPQN5mAJU=:YLjnjZCrfB2ojaYQ76z1cQ 7DVYAeSafLg/U9mqKWMVerUNpPmrkp8PicVhaXeSea4QA1Yztdq1hzkgGplr58OOH/uOKEsVN /rEvtO0MzCqibeTnADfhJlmJ3vpdQaoJizWf0BnVMKOpZVadVdyjkvtDl2xwy+Tc6aVg5cUjY Kl1dBcZAvxiIRpW2amHc68ibpuHMBwIS8BTtf21ff9ZchxXB69my4/5pVAy57WQUPd9YsgFAb eG2/j4gvDJA6iLLqEZOHX2OSDshyDOw5080dYkOKYU1/A5TO1cDHLMm7Ty9pfxHXyILWPKg0k pCcK8CH+ql8/Ei5lqwZrlJovUXFi372XdN5qaZ17zOtHDirDHdoVJsjKaT+20c+gvvv+0467r 2n30PPmnreiKYcM8HhklxmBpXP6RT/yMP86OmyBlSfAoJwiQ6gj91eYHHwLI4o519+GM20u+E Q/uhHkyfNF3nbOUT9U4fL2DtgcY+rVfpclOIS+wSLr8HESyPnyk/kq+tqLK4hebFkD4qrxOOd AQmObcsOmKGmLRy0FU++mU= X-Spam-Status: No, score=-98.6 required=5.0 tests=BAYES_00, BODY_8BITS, GOOD_FROM_CORINNA_CYGWIN, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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: Tue, 04 May 2021 12:27:54 -0000 On May 4 02:45, Mark Geisert wrote: > Mark Geisert wrote: > > Ken Brown via Cygwin wrote: > > > On 5/3/2021 8:57 AM, Maximilian.Blenk--- via Cygwin wrote: > > > > Incorrect Behavior: > > > > Server: > > > > $ python3.7 server.py > > > > starting up on ./uds_socket > > > > waiting for a connection > > > > Traceback (most recent call last): > > > >    File "server.py", line 27, in > > > >      connection, client_address = sock.accept() > > > >    File "/usr/lib/python3.7/socket.py", line 214, in accept > > > >      sock = socket(self.family, self.type, self.proto, fileno=fd) > > > >    File "/usr/lib/python3.7/socket.py", line 151, in __init__ > > > >      _socket.socket.__init__(self, family, type, proto, fileno) > > > > SystemError: > > > objects> returned NULL without setting an error > > > > > > > > Client: > > > > $ python3.7 client.py > > > > connecting to ./uds_socket > > > > sending b'This is the message.  It will be repeated.' > > > > closing socket > > > > Traceback (most recent call last): > > > >    File "client.py", line 27, in > > > >      data = sock.recv(16) > > > > ConnectionResetError: [Errno 104] Connection reset by peer > > > > > > I wonder if this has the same cause as the problem reported here: > > > > > >    https://cygwin.com/pipermail/cygwin/2021-February/247884.html > > > > > > Mark, can you check that? > > This issue is indeed related to the Python patch released to Python > 3.{6,7,8} but not Python 3.5 or earlier. I'm discussing here because the > situation involves Python internals doing socket operations and Cygwin's > AF_UNIX support is shaky in some aspects (that Ken's work will likely fix to > the relief of everyone!). > > The purpose of the Python patch is to disable the normal peer handshake that > starts each AF_UNIX connection. So whenever a Python app obtains an AF_UNIX > socket, either from socket() or accept(), the internal routine that inits > Python-level state was patched to call setsockopt() to turn off the > handshake. > > But it turns out that fhandler_socket_local::accept4() sets the socket's > connect_state to "connected", on line fhandler_socket_local.cc:1086. Then > when the wrapping Python patch calls setsockopt() we end up in > ::af_local_set_no_getpeereid(), which is good, but the socket is marked > "connected" so the result is an EALREADY error that rather clumsily knocks > out both the server and client apps. You're supposed to call the special setsockopt(SO_PEERCRED) on the accepting socket. The no_getpeereid property is inherited by the accepted socket. Corinna