[New-bugs-announce] [issue16133] asyncore.dispatcher.recv doesn't handle EAGAIN / EWOULDBLOCK
Nidan
report at bugs.python.org
Thu Oct 4 18:06:32 CEST 2012
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 <report at bugs.python.org>
<http://bugs.python.org/issue16133>
_______________________________________
More information about the New-bugs-announce
mailing list