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 Nidan
Recipients Nidan
Date 2012-10-04.16:06:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1349366792.42.0.417654527681.issue16133@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-10-04 16:06:32Nidansetrecipients: + Nidan
2012-10-04 16:06:32Nidansetmessageid: <1349366792.42.0.417654527681.issue16133@psf.upfronthosting.co.za>
2012-10-04 16:06:32Nidanlinkissue16133 messages
2012-10-04 16:06:32Nidancreate