summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--waitress/channel.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/waitress/channel.py b/waitress/channel.py
index a377a54..e717dd7 100644
--- a/waitress/channel.py
+++ b/waitress/channel.py
@@ -151,7 +151,7 @@ class HTTPChannel(wasyncore.dispatcher, object):
self.will_close = True
if self.will_close:
- self.handle_close()
+ self.handle_close(lock=False)
def readable(self):
# We might want to create a new task. We can only do this if:
@@ -168,7 +168,7 @@ class HTTPChannel(wasyncore.dispatcher, object):
except socket.error:
if self.adj.log_socket_errors:
self.logger.exception('Socket error')
- self.handle_close()
+ self.handle_close(lock=True)
return
if data:
self.last_activity = time.time()
@@ -274,10 +274,11 @@ class HTTPChannel(wasyncore.dispatcher, object):
return False
- def handle_close(self):
- # avoid closing the outbufs while a task is potentially adding data
- # to them in write_soon
- with self.outbuf_lock:
+ def handle_close(self, lock=True):
+ # NB: default to True for when asyncore calls this function directly
+ if lock:
+ self.outbuf_lock.acquire()
+ try:
for outbuf in self.outbufs:
try:
outbuf.close()
@@ -285,6 +286,9 @@ class HTTPChannel(wasyncore.dispatcher, object):
self.logger.exception(
'Unknown exception while trying to close outbuf')
self.connected = False
+ finally:
+ if lock:
+ self.outbuf_lock.release()
wasyncore.dispatcher.close(self)
def add_channel(self, map=None):