From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-developers@cygwin.com
Subject: Re: python > 3.5: Issue with unix domain sockets
Date: Tue, 4 May 2021 14:27:50 +0200 [thread overview]
Message-ID: <YJE9xltXzlOoLF6a@calimero.vinschen.de> (raw)
In-Reply-To: <134fa003-836f-1184-79eb-e31dfd852a64@maxrnd.com>
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 <module>
> > > > 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: <slot wrapper '__init__' of '_socket.socket'
> > > > 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 <module>
> > > > 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
next prev parent reply other threads:[~2021-05-04 12:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1620046759893.5340@bmw.de>
[not found] ` <2cde4128-6a3d-7431-6608-a2184d23964a@cornell.edu>
[not found] ` <af597ace-e986-35a0-9983-99256c440791@maxrnd.com>
2021-05-04 9:45 ` Mark Geisert
2021-05-04 12:27 ` Corinna Vinschen [this message]
2021-05-05 5:04 ` Mark Geisert
2021-05-06 8:35 ` Corinna Vinschen
2021-05-06 9:24 ` Mark Geisert
2021-05-06 10:30 ` Corinna Vinschen
2021-05-06 12:18 ` Marco Atzeri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YJE9xltXzlOoLF6a@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-developers@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).