From b6278183da334cfc451b8d14c9a60b9eee332c66 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 24 Jul 2010 17:50:34 +0100 Subject: [PATCH] whoops, overlapping connections race condition! --- ProxyServer.py | 16 +++++++++------- httpd.py | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ProxyServer.py b/ProxyServer.py index 327a4d1..4816cdc 100644 --- a/ProxyServer.py +++ b/ProxyServer.py @@ -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 diff --git a/httpd.py b/httpd.py index 7daf054..d86c3be 100644 --- 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 -- 2.30.2