New submission from adamhj <ada...@gmail.com>:

i found 2 relative bugs in asyncore.dispatcher_with_send class:

one is in the asyncore.dispatcher_with_send.writable():
    def writable(self):
        return (not self.connected) or len(self.out_buffer)
why is a not connected connection writable? i think this is definitely a bug
my fix:
    def writable(self):
        return self.connected and len(self.out_buffer)

another bug is more obscure, i'm not sure is it a bug or something should be 
handled by user(programmer)

the bug is also in asyncore.dispatcher_with_send class, and maybe also in 
asyncore.dispatcher class. asyncore.dispatcher uses unblocking socket to handle 
network missions, when we use the connect() method of dispatcher to establish 
the socket, it will call socket.connect_ex() method to create the connection, 
however, socket.connect_ex() may return 10035(EWOULDBLOCK) as it is an 
unblocking socket indicates that the connection creating is not finished yet, 
if we call dispatcher.connect() immediately after .connect(), socket error 
10057 may be raised, indicating that the socket is not established yet, then 
the asyncore main loop catches this exception, and calls handle_error(in my 
case i close the connection in handle_error so the connection which would be 
established with no problem breaks), i think there should be a connection state 
check in asyncore.dispatcher.send(), or at least in 
asyncore.dispatcher_with_send.send.

my fix for asyncore.dispatcher_with_send.send():
    def send(self, data):
        if self.debug:
            self.log_info('sending %s' % repr(data))
        self.out_buffer = self.out_buffer + data
        if self.connected:        # do not call send() if connection is
            self.initiate_send()  # not established yet, just put data 
                                  # in buffer

for the second bug, to reproduce it, just create a unblocking socket to a 
remote, long delay port with socket.connect_ex and call send immediately

----------
components: Library (Lib)
messages: 152494
nosy: adamhj
priority: normal
severity: normal
status: open
title: bug in asyncore.dispatcher_with_send
type: behavior
versions: Python 2.7

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

Reply via email to