]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Catch all exceptions, not just {OS,IO}Error in IOLoop.remove_handler.
authorBen Darnell <ben@bendarnell.com>
Fri, 7 Dec 2012 19:19:48 +0000 (14:19 -0500)
committerBen Darnell <ben@bendarnell.com>
Fri, 7 Dec 2012 19:27:53 +0000 (14:27 -0500)
Attempting to remove a non-existent fd raises IOError on epoll
but KeyError on kqueue; this change swallows any exeption to make
both platforms consistent.

tornado/ioloop.py
tornado/platform/twisted.py
tornado/test/ioloop_test.py

index 3c9b05b9a998371cfa906b5545f0b48e72c0ccba..1db5e5a93d8d8f6c26c673f78df840bcc32996ca 100644 (file)
@@ -442,7 +442,7 @@ class PollIOLoop(IOLoop):
         self._events.pop(fd, None)
         try:
             self._impl.unregister(fd)
-        except (OSError, IOError):
+        except Exception:
             gen_log.debug("Error deleting fd from IOLoop", exc_info=True)
 
     def set_blocking_signal_threshold(self, seconds, action):
index 6c3cbf967a70228e5e24422067a22d57ae3e5239..4536837f30c6da62b7c2cddfcb415db727d37d0d 100644 (file)
@@ -431,6 +431,8 @@ class TwistedIOLoop(tornado.ioloop.IOLoop):
                 self.reactor.removeWriter(self.fds[fd])
 
     def remove_handler(self, fd):
+        if fd not in self.fds:
+            return
         self.fds[fd].lost = True
         if self.fds[fd].reading:
             self.reactor.removeReader(self.fds[fd])
index 569b03ca531172121d2646d99195f188c907e601..fa403c0c769b0dc97d8ddd51bbd21ac56d7a6cf9 100644 (file)
@@ -65,6 +65,15 @@ class TestIOLoop(AsyncTestCase):
             self.io_loop.remove_handler(sock.fileno())
             sock.close()
 
+    def test_remove_without_add(self):
+        # remove_handler should not throw an exception if called on an fd
+        # was never added.
+        sock, port = bind_unused_port()
+        try:
+            self.io_loop.remove_handler(sock.fileno())
+        finally:
+            sock.close()
+
     def test_add_callback_from_signal(self):
         # cheat a little bit and just run this normally, since we can't
         # easily simulate the races that happen with real signal handlers