This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients asvetlov, methane, pitrou, vstinner, yselivanov
Date 2017-12-15.03:42:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1513309369.41.0.213398074469.issue32331@psf.upfronthosting.co.za>
In-reply-to
Content
On Linux, socket type is both a socket type and a bit mask (of SOCK_CLOEXEC and SOCK_NONBLOCK).  Therefore, anyone who write code like 'if sock.type == SOCK_STREAM' writes non-portable code, that occasionally breaks on Linux.  

This caused some hard to spot bugs in asyncio already: https://bugs.python.org/issue27456  -- this one was discovered only 1 year after the actual change.

On Linux, in 'include/linux/net.h' there's a SOCK_TYPE_MASK macro defined to 0xF.  The idea is that on Linux you should mask socket type before comparing it to SOCK_STREAM or other socket types.

Using socket.SOCK_NONBLOCK on Python was always error-prone even if one targets only Linux.  For instance, socket.type won't be updated to include SOCK_NONBLOCK if the socket was updated via ioctl call directly.

Therefore, I propose to fix socket.type getter to always (on Linux) apply that mask in Python.
History
Date User Action Args
2017-12-15 03:42:49yselivanovsetrecipients: + yselivanov, pitrou, vstinner, asvetlov, methane
2017-12-15 03:42:49yselivanovsetmessageid: <1513309369.41.0.213398074469.issue32331@psf.upfronthosting.co.za>
2017-12-15 03:42:49yselivanovlinkissue32331 messages
2017-12-15 03:42:47yselivanovcreate