New submission from Nidan:

I recently had lots of the following exception:
error: uncaptured python exception, closing channel 
<servercore_persistent.ConnectionHandler connected 127.0.0.1:53609 at 
0x8d27eec> (<class 'socket.error'>:[Errno 11] Resource temporarily unavailable 
[/usr/lib/python2.7/asynchat.py|handle_read|110] 
[/usr/lib/python2.7/asyncore.py|recv|384])

Error 11 is EAGAIN or EWOULDBLOCK, so asyncore/asynchat tries to read from a 
nonblocking socket which has no data available. Since this is a temporary error 
the socket shouldn't be closed.

The bug can be fixed by changing asyncore.dispatcher.recv to
    def recv(self, buffer_size):
        try:
            data = self.socket.recv(buffer_size)
            if not data:
                # a closed connection is indicated by signaling
                # a read condition, and having recv() return 0.
                self.handle_close()
                return ''
            else:
                return data
        except socket.error, why:
            # winsock sometimes throws ENOTCONN
            if why.args[0] in _DISCONNECTED:
                self.handle_close()
                return ''
            elif why.args[0] in (EAGAIN, EWOULDBLOCK):
                return ''
            else:
                raise

While looking at the source I also saw that asyncore.dispatcher.send and 
.connect check against EWOULDBLOCK but not against EAGAIN. Since both constants 
may have different values and POSIX allows to return either of them these 
functions should check against both error constants.

----------
components: Library (Lib)
messages: 171967
nosy: Nidan
priority: normal
severity: normal
status: open
title: asyncore.dispatcher.recv doesn't handle EAGAIN / EWOULDBLOCK
type: behavior
versions: Python 2.7, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to