[New-bugs-announce] [issue24732] 3.5.0b3 Windows accept() on unready non-blocking socket raises PermissionError

Bryan G. Olson report at bugs.python.org
Mon Jul 27 04:13:48 CEST 2015


New submission from Bryan G. Olson:

In Python 3.4 on Windows 7, the code:

    import socket
    sock = socket.socket()
    sock.bind(('127.0.0.1', 52384))
    sock.listen(5)
    sock.setblocking(False)
    csock, addr = sock.accept()

Raised:

    Traceback (most recent call last):
      File "socket_bug_test.py", line 8, in <module>
        csock, addr = sock.accept()
      File "c:\bin\Python34\lib\socket.py", line 187, in accept
        fd, addr = self._accept()
    BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately

In Python 3.5.0b3 on the same system, it is raising:

    Traceback (most recent call last):
      File "socket_bug_test.py", line 8, in <module>
        csock, addr = sock.accept()
      File "c:\bin\Python35\lib\socket.py", line 195, in accept
        fd, addr = self._accept()
    PermissionError: [WinError 5] Access is denied

This is a problem for other parts of the Standard Library. I hit it playing with asyncio, where in Lib\asyncio\selector_events.py the function BaseSelectorEventLoop._sock_accept() is prepared for an unready socket to raise BlockingIOError or InterruptedError, but does not catch the WinError:

        try:
            conn, address = sock.accept()
            conn.setblocking(False)
        except (BlockingIOError, InterruptedError):
            self.add_reader(fd, self._sock_accept, fut, True, sock)
        except Exception as exc:
            fut.set_exception(exc)
        else:
            fut.set_result((conn, address))

There are other calls to accept in accept() in asyncio, that I haven't tested but also look adversely affected.

The older asyncore module looks to have a similar problem. In dispatcher.accept(): 

    def accept(self):
        # XXX can return either an address pair or None
        try:
            conn, addr = self.socket.accept()
        except TypeError:
            return None
        except OSError as why:
            if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
                return None
            else:
                raise
        else:
            return conn, addr

The 'except OSError as why' will catch the WinError, but why.args[0] will be errno.EACCES = 13, permission denied, which is not equal to any of anticipated errors.


My system according to Python:

    >>> import sys
    >>> sys.version
    '3.5.0b3 (default, Jul  5 2015, 07:00:46) [MSC v.1900 64 bit (AMD64)]'
    >>> sys.getwindowsversion()
    sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')

That's Windows 7 Professional, 64-bit, with Service pack 1. It has an AND Phenom II X6 1055T Processor 2.8 GHz, and 8GB of memory.

----------
components: Windows
messages: 247452
nosy: bryangeneolson, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: 3.5.0b3 Windows accept() on unready non-blocking socket raises PermissionError
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24732>
_______________________________________


More information about the New-bugs-announce mailing list