[Zope-dev] Handling of ECONNRESET socket error in asyncore.py

Oliver Bleutgen myzope@gmx.net
Fri, 23 Aug 2002 23:06:45 +0200


It just thought about the fact that zope on linux seemingly does ignore 
when the user presses of the stop on his browser.
I.e., if you access a e.g. long running python(script) and press "Stop" 
on the browser and you'll see the thread which runs the script is still 
working. Extremely ugly IMO.

Well, it also happens on win. I just looked at asyncore.dispatcher, and 
there's the recv() method:

def recv (self, buffer_size):
         try:
            ...
         except socket.error, why:
             # winsock sometimes throws ENOTCONN
             if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
                 self.handle_close()
                 return ''
             else:
                 raise socket.error, why

The browser closes the connection when the Stop button is pressed, that 
means that the recieving end gets a RST, and that seems to throw a 
socket.error, with why[0] == ECONNRESET. Well, I know jack about the 
python socket class, but a strategical placed "print" tells more than a 
thousand words ;-).

handle_close() doesn't also do much, just logs and closes the 
connection. So, the poor thread never does never find out about the fact 
that all his work is for nothing, and happily continues.

Can't this be fixed anyhow?

cheers,
oliver