From: Alexander Clausen Date: Sat, 12 Dec 2020 05:58:06 +0000 (+0100) Subject: WaitIterator: don't re-use _running_future X-Git-Tag: v6.2.0b1~58^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f3f24b7198f7f9b6aa41fcccc1e4e4151e55c26;p=thirdparty%2Ftornado.git WaitIterator: don't re-use _running_future 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 --- diff --git a/tornado/gen.py b/tornado/gen.py index cab968937..2d2038551 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -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