cleanup after remote end dies
authorlkcl <lkcl@teenymac.(none)>
Thu, 15 Jul 2010 14:33:33 +0000 (15:33 +0100)
committerlkcl <lkcl@teenymac.(none)>
Thu, 15 Jul 2010 14:33:33 +0000 (15:33 +0100)
ProxyServer.py
httpd.py

index 15380f6a0d3131da968b9bd7b55dd827ffdbce66..786e550ff1249d25107dcca3ed9b0da7e47a9bf3 100644 (file)
@@ -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()
             
index e87272ed81412974714a5f564d1e0dd7a947352b..a2aadb3cf4c31a64fc2d3e2f6011cb3f3ff3d129 100644 (file)
--- 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')