From b54a2c6223a9c4e06d18d1725c6ac29246d941a3 Mon Sep 17 00:00:00 2001 From: lkcl Date: Thu, 15 Jul 2010 15:33:33 +0100 Subject: [PATCH] cleanup after remote end dies --- ProxyServer.py | 7 +++++-- httpd.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ProxyServer.py b/ProxyServer.py index 15380f6..786e550 100644 --- a/ProxyServer.py +++ b/ProxyServer.py @@ -283,8 +283,11 @@ class ProxyServerRequestHandler(object): p.serving = False except httpd.ConnectionClosed: - # whoops... - raise httpd.ConnectionClosed + # whoops, remote end has died: remove client and + # remove proxy session, we cannot do anything else, + # there's nothing there to talk to. + self.client.removeConnection() + self.proxies.pop(session) except: print traceback.print_exc() diff --git a/httpd.py b/httpd.py index e87272e..a2aadb3 100644 --- a/httpd.py +++ b/httpd.py @@ -280,7 +280,11 @@ class Protocol(object): except ConnectionClosed: #yield self.connectionClosed() if _debug: print 'parse connection closed' + #yield self.server.queue.put((self, None)) # close connection + def removeConnection(self): + yield self.server.queue.put((self, None)) # close connection + def writeMessage(self, message): try: yield self.stream.write(message) @@ -676,6 +680,13 @@ class HTTPServer(object): if not client: # if the server aborted abnormally, break # hence close the listener. if _debug: print 'client connection received', client, msg + + if msg is None: + yield client.connectionClosed() + session = client.session + del self.clients[session] + continue + # if client.objectEncoding != 0 and client.objectEncoding != 3: if client.objectEncoding != 0: yield client.rejectConnection(reason='Unsupported encoding ' + str(client.objectEncoding) + '. Please use NetConnection.defaultObjectEncoding=ObjectEncoding.AMF0') -- 2.30.2