bpo-37658: Actually return result in race condition (GH-29202) (GH-29832)

(cherry picked from commit 934a826237)

Co-authored-by: Sam Bull <aa6bs0@sambull.org>

Co-authored-by: Sam Bull <aa6bs0@sambull.org>
This commit is contained in:
Miss Islington (bot) 2021-11-30 05:39:13 -08:00 committed by GitHub
parent 031e2bb332
commit 99a9b34331
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 36 deletions

View file

@ -449,11 +449,9 @@ async def wait_for(fut, timeout, *, loop=None):
await _cancel_and_wait(fut, loop=loop)
try:
fut.result()
return fut.result()
except exceptions.CancelledError as exc:
raise exceptions.TimeoutError() from exc
else:
raise exceptions.TimeoutError()
waiter = loop.create_future()
timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
@ -489,11 +487,9 @@ async def wait_for(fut, timeout, *, loop=None):
# exception, we should re-raise it
# See https://bugs.python.org/issue40607
try:
fut.result()
return fut.result()
except exceptions.CancelledError as exc:
raise exceptions.TimeoutError() from exc
else:
raise exceptions.TimeoutError()
finally:
timeout_handle.cancel()