From: Ben Darnell Date: Mon, 27 Sep 2010 21:08:56 +0000 (-0700) Subject: In the select()-based IOLoop, always listen for reads so we can tell X-Git-Tag: v1.2.0~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1221865747ecfde69a0463b9a0d77b3c5b87f320;p=thirdparty%2Ftornado.git In the select()-based IOLoop, always listen for reads so we can tell when the other side closed the connection. Closes #37. --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 02ab73c46..ea34e0fe6 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -496,7 +496,12 @@ class _Select(object): def register(self, fd, events): if events & IOLoop.READ: self.read_fds.add(fd) if events & IOLoop.WRITE: self.write_fds.add(fd) - if events & IOLoop.ERROR: self.error_fds.add(fd) + if events & IOLoop.ERROR: + self.error_fds.add(fd) + # Closed connections are reported as errors by epoll and kqueue, + # but as zero-byte reads by select, so when errors are requested + # we need to listen for both read and error. + self.read_fds.add(fd) def modify(self, fd, events): self.unregister(fd) diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 181ffe5ac..372fc6872 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -113,7 +113,3 @@ class ConnectionCloseTest(AsyncHTTPTestCase, LogTrapTestCase): def on_connection_close(self): logging.info('connection closed') self.stop() - -if tornado.ioloop._poll is tornado.ioloop._Select: - # select-based ioloop does not detect closed connections promptly - del ConnectionCloseTest diff --git a/tornado/web.py b/tornado/web.py index b79399add..a5bdb876c 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -159,12 +159,6 @@ class RequestHandler(object): You may override this to clean up resources associated with long-lived connections. - Note that the select()-based implementation of IOLoop does not detect - closed connections and so this method will not be called until - you try (and fail) to produce some output. The epoll- and kqueue- - based implementations should detect closed connections even while - the request is idle. - Proxies may keep a connection open for a time (perhaps indefinitely) after the client has gone away, so this method may not be called promptly after the end user closes their