Author: justi9
Date: 2008-04-09 14:25:42 -0400 (Wed, 09 Apr 2008)
New Revision: 1896
Modified:
mgmt/cumin/python/wooly/wsgiserver.py
Log:
Add some state to HTTPConnection, so that we can mark it aborted and
close existing keepalive connections abruptbly. This avoids an
interminable server shutdown.
Modified: mgmt/cumin/python/wooly/wsgiserver.py
===================================================================
--- mgmt/cumin/python/wooly/wsgiserver.py 2008-04-09 16:50:25 UTC (rev 1895)
+++ mgmt/cumin/python/wooly/wsgiserver.py 2008-04-09 18:25:42 UTC (rev 1896)
@@ -601,6 +601,7 @@
self.socket = sock
self.addr = addr
self.server = server
+ self.__aborted = False
# Copy the class environ into self.
self.environ = self.environ.copy()
@@ -633,11 +634,17 @@
# Until we do DNS lookups, omit REMOTE_HOST
self.environ["REMOTE_ADDR"] = self.addr[0]
self.environ["REMOTE_PORT"] = str(self.addr[1])
+
+ def abort(self):
+ self.__aborted = True
def communicate(self):
"""Read each request and respond appropriately."""
try:
while True:
+ if self.__aborted:
+ return
+
# (re)set req to None so that if something goes wrong in
# the RequestHandlerClass constructor, the error doesn't
# get written to the previous request.
@@ -645,6 +652,7 @@
req = self.RequestHandlerClass(self)
# This order of operations should guarantee correct pipelining.
req.parse_request()
+
if not req.ready:
return
req.respond()
@@ -703,6 +711,7 @@
def __init__(self, server):
self.ready = False
self.server = server
+ self.currentConnection = None
threading.Thread.__init__(self)
def run(self):
@@ -713,6 +722,8 @@
if conn is _SHUTDOWNREQUEST:
return
+ self.currentConnection = conn
+
try:
conn.communicate()
finally:
@@ -998,6 +1009,8 @@
worker = self._workerThreads.pop()
if worker is not current and worker.isAlive():
try:
+ if worker.currentConnection:
+ worker.currentConnection.abort()
worker.join()
except AssertionError:
pass
Show replies by date