whoops, overlapping connections race condition!
authorLuke Leighton <lkcl@lkcl.net>
Sat, 24 Jul 2010 16:50:34 +0000 (17:50 +0100)
committerLuke Leighton <lkcl@lkcl.net>
Sat, 24 Jul 2010 16:50:34 +0000 (17:50 +0100)
ProxyServer.py
httpd.py

index 327a4d111490022d6c37f60eb859fea98c751557..4816cdc37c1d27a2cb44063ca29969ebf9300d48 100644 (file)
@@ -139,25 +139,26 @@ class ProxyServerRequestHandler(object):
             proxy.connect()
             self.proxies[session] = proxy
 
-        multitask.add(self.proxy_relay(reqtype))
+        yield self.proxy_relay(reqtype)
 
-        return True
+        #while p.serving:
+        #    (yield multitask.sleep(0.01))
+
+        raise StopIteration
 
     def onPOST(self, client, *args):
         """Serve a POST request."""
-        return self.on_query(client, "POST", *args)
+        yield self.on_query(client, "POST", *args)
 
     def onGET(self, client, *args):
         """Serve a GET request."""
-        return self.on_query(client, "GET", *args)
+        yield self.on_query(client, "GET", *args)
 
     def proxy_relay(self, reqtype):
 
         session = self.client.session 
         p = self.proxies[session]
 
-        #while p.serving:
-        #    (yield multitask.sleep(0.01))
         p.serving = True
 
         try:
@@ -292,6 +293,7 @@ class ProxyServerRequestHandler(object):
                     print 'proxy wants client to close_connection'
                 try:
                     yield self.client.connectionClosed()
+                    p.serving = False
                     raise httpd.ConnectionClosed
                 except httpd.ConnectionClosed:
                     if self.debuglevel > 0:
@@ -310,6 +312,6 @@ class ProxyServerRequestHandler(object):
             if self.debuglevel > 0:
                 print traceback.print_exc()
             
-
+        p.serving = False
         raise StopIteration
 
index 7daf0546ce757a4cfa19f81e5a95d240099a7637..d86c3bece9c7e4b661897c216c71ab25d1f3984a 100644 (file)
--- a/httpd.py
+++ b/httpd.py
@@ -507,7 +507,8 @@ class HTTPServer(object):
                         if _debug:
                             print methodname, dir(inst)
                         method = getattr(inst, methodname, None)
-                        result = method(client, msg)
+                        yield method(client, msg)
+                        result = None
                         close_connection = msg.close_connection
                         if _debug:
                             print "close connection", close_connection