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 vmagamedov
Recipients j1m, python-dev, socketpair, vmagamedov, vstinner, yselivanov
Date 2017-11-02.15:48:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Seems like this fix is incomplete. It contains this check:

    sock.type == socket.SOCK_STREAM

But sock.type is not only a type (at least in Linux and FreeBSD), it also may contain SOCK_NONBLOCK and SOCK_CLOEXEC flags. So I'm hitting the same problem: on the Linux in asyncio I have:

    > sock.type == socket.SOCK_STREAM | socket.SOCK_NONBLOCK == 2049

So this check isn't working and TCP_NODELAY still disabled by default.


Linux has SOCK_TYPE_MASK definition equal to 0xf, but I can't find such definition in the FreeBSD sources. And I don't know how to reliably and with forward compatibility check sock.type without calling getsockopt() syscall.

Currently I have a fix in my project, where:

    _sock_type_mask = 0xf if hasattr(socket, 'SOCK_NONBLOCK') else 0xffffffff

And then in my own _set_nodelay(sock) function:

    sock.type & _sock_type_mask == socket.SOCK_STREAM

Should I make a pull request or someone knows more reliable check? Or it is ok to add one more syscall?

    sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE) == socket.SOCK_STREAM
Date User Action Args
2017-11-02 15:48:27vmagamedovsetrecipients: + vmagamedov, vstinner, j1m, socketpair, python-dev, yselivanov
2017-11-02 15:48:27vmagamedovsetmessageid: <>
2017-11-02 15:48:27vmagamedovlinkissue27456 messages
2017-11-02 15:48:27vmagamedovcreate