From 7b48b1bb34f97e4adf32c12a987ff593dc536aef Mon Sep 17 00:00:00 2001 From: Chayim Date: Wed, 22 Mar 2023 18:04:42 +0200 Subject: AsyncIO Race Condition Fix (#2639) --- redis/asyncio/client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'redis/asyncio/client.py') diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 3d59016..5c0b546 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -1349,10 +1349,16 @@ class Pipeline(Redis): # lgtm [py/init-calls-subclass] conn = cast(Connection, conn) try: - return await conn.retry.call_with_retry( - lambda: execute(conn, stack, raise_on_error), - lambda error: self._disconnect_raise_reset(conn, error), + return await asyncio.shield( + conn.retry.call_with_retry( + lambda: execute(conn, stack, raise_on_error), + lambda error: self._disconnect_raise_reset(conn, error), + ) ) + except asyncio.CancelledError: + # not supposed to be possible, yet here we are + await conn.disconnect(nowait=True) + raise finally: await self.reset() -- cgit v1.2.1