diff options
author | Chris McDonough <chrism@plope.com> | 2012-01-02 17:32:24 -0500 |
---|---|---|
committer | Chris McDonough <chrism@plope.com> | 2012-01-02 17:32:24 -0500 |
commit | 359257a9da47b398f68b84b12e07283ead9414b4 (patch) | |
tree | 045a70f779747afa9ec0291f08257b977b395946 | |
parent | 5b3f2c0b3f30fb6df7804b83b585e3be5169d347 (diff) | |
download | waitress-359257a9da47b398f68b84b12e07283ead9414b4.tar.gz |
- Channel timeout cleanup was broken.
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | waitress/channel.py | 11 | ||||
-rw-r--r-- | waitress/tests/test_channel.py | 6 |
3 files changed, 17 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ced8838..8ce248d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -11,6 +11,8 @@ Bug Fixes - Minor resource cleanups during tests. +- Channel timeout cleanup was broken. + 0.3 (2012-01-02) ---------------- diff --git a/waitress/channel.py b/waitress/channel.py index 5efe44d..48916a8 100644 --- a/waitress/channel.py +++ b/waitress/channel.py @@ -74,13 +74,19 @@ class HTTPChannel(logging_dispatcher, object): asyncore.dispatcher.__init__(self, sock, map=map) def writable(self): - return bool(self.outbuf) + # if there's data in the out buffer or we've been instructed to close + # the channel (possibly by our server maintenance logic), run + # handle_write + return bool(self.outbuf) or self.will_close def handle_write(self): - # Precondition: there's data in the out buffer to be sent + # Precondition: there's data in the out buffer to be sent, or + # there's a pending will_close request if not self.connected: + # we dont want to close the channel twice return + # try to flush any pending output if not self.requests: # 1. There are no running tasks, so we don't need to try to lock # the outbuf before sending @@ -116,6 +122,7 @@ class HTTPChannel(logging_dispatcher, object): if self.adj.log_socket_errors: self.logger.exception('Socket error') self.will_close = True + if self.will_close: self.handle_close() diff --git a/waitress/tests/test_channel.py b/waitress/tests/test_channel.py index e397f90..b4d1d5a 100644 --- a/waitress/tests/test_channel.py +++ b/waitress/tests/test_channel.py @@ -29,6 +29,12 @@ class TestHTTPChannel(unittest.TestCase): inst.outbuf = '' self.assertFalse(inst.writable()) + def test_writable_nothing_in_outbuf_will_close(self): + inst, sock, map = self._makeOneWithMap() + inst.outbuf = '' + inst.will_close = True + self.assertTrue(inst.writable()) + def test_handle_write_not_connected(self): inst, sock, map = self._makeOneWithMap() inst.outbuf = '' |