]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
WaitIterator: don't re-use _running_future
authorAlexander Clausen <alex@gc-web.de>
Sat, 12 Dec 2020 05:58:06 +0000 (06:58 +0100)
committerAlexander Clausen <alex@gc-web.de>
Sat, 12 Dec 2020 05:58:06 +0000 (06:58 +0100)
When used with asyncio.Future, WaitIterator may skip indices in some
cases. This is caused by multiple _return_result calls after another,
without having the chain_future call finish in between. This is fixed
here by not hanging on to the _running_future anymore, which forces
subsequent _return_result calls to add to _finished, instead of causing
the previous result to be silently dropped.

Fixes #2034

tornado/gen.py

index cab9689375043d5671d38d60b169186665a31d12..2d203855131561145f15e986a910b0fb7c93a538 100644 (file)
@@ -400,7 +400,7 @@ class WaitIterator(object):
         self._running_future = Future()
 
         if self._finished:
-            self._return_result(self._finished.popleft())
+            return self._return_result(self._finished.popleft())
 
         return self._running_future
 
@@ -418,9 +418,13 @@ class WaitIterator(object):
             raise Exception("no future is running")
         chain_future(done, self._running_future)
 
+        res = self._running_future
+        self._running_future = None
         self.current_future = done
         self.current_index = self._unfinished.pop(done)
 
+        return res
+
     def __aiter__(self) -> typing.AsyncIterator:
         return self