]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix a StackContext leak introduced by the delayed IOStream callbacks
authorBen Darnell <ben@bendarnell.com>
Sun, 15 May 2011 05:35:23 +0000 (22:35 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 15 May 2011 05:35:23 +0000 (22:35 -0700)
tornado/iostream.py

index cb67f3ae4e885211d058590d611cf8c9a130ffd5..38c1a2ba3834711d6e78bef48a9cb626a92c6698 100644 (file)
@@ -251,7 +251,13 @@ class IOStream(object):
         #   non-reentrant mutexes
         # * Ensures that the try/except in wrapper() is run outside
         #   of the application's StackContexts
-        self.io_loop.add_callback(wrapper)
+        with stack_context.NullContext():
+            # stack_context was already captured in callback, we don't need to
+            # capture it again for IOStream's wrapper.  This is especially
+            # important if the callback was pre-wrapped before entry to
+            # IOStream (as in HTTPConnection._header_callback), as we could
+            # capture and leak the wrong context here.
+            self.io_loop.add_callback(wrapper)
 
     def _handle_read(self):
         while True: