From 998203113f099cbd4951695fedd78225b7b97754 Mon Sep 17 00:00:00 2001 From: DM_ Date: Tue, 22 Feb 2022 09:35:32 +0800 Subject: [PATCH] fix: Task exception was never retrieved when continue_ race with page closed event closes #1165 --- playwright/_impl/_network.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/playwright/_impl/_network.py b/playwright/_impl/_network.py index cd582d828..91511b1f8 100644 --- a/playwright/_impl/_network.py +++ b/playwright/_impl/_network.py @@ -285,10 +285,13 @@ async def _race_with_page_close(self, future: Coroutine) -> None: # When page closes or crashes, we catch any potential rejects from this Route. # Note that page could be missing when routing popup's initial request that # does not have a Page initialized just yet. + fut = asyncio.create_task(future) await asyncio.wait( - [asyncio.create_task(future), page._closed_or_crashed_future], + [fut, page._closed_or_crashed_future], return_when=asyncio.FIRST_COMPLETED, ) + if page._closed_or_crashed_future.done(): + await asyncio.gather(fut, return_exceptions=True) else: await future