Skip to content

Commit 7bebfe5

Browse files
committed
guard
1 parent 318b114 commit 7bebfe5

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

redis/asyncio/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,10 +1385,16 @@ async def execute(self, raise_on_error: bool = True):
13851385
conn = cast(Connection, conn)
13861386

13871387
try:
1388-
return await conn.retry.call_with_retry(
1389-
lambda: execute(conn, stack, raise_on_error),
1390-
lambda error: self._disconnect_raise_reset(conn, error),
1388+
return await asyncio.shield(
1389+
conn.retry.call_with_retry(
1390+
lambda: execute(conn, stack, raise_on_error),
1391+
lambda error: self._disconnect_raise_reset(conn, error),
1392+
)
13911393
)
1394+
except asyncio.CancelledError:
1395+
# not supposed to be possible, yet here we are
1396+
await connection.disconnect(nowait=True)
1397+
raise
13921398
finally:
13931399
await self.reset()
13941400

redis/asyncio/cluster.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,18 @@ async def execute_command(self, *args: Any, **kwargs: Any) -> Any:
10021002
await connection.send_packed_command(connection.pack_command(*args), False)
10031003

10041004
# Read response
1005+
return await asyncio.shield(
1006+
self._parse_and_release(connection, args[0], **kwargs)
1007+
)
1008+
1009+
async def _parse_and_release(self, connection, *args, **kwargs):
10051010
try:
1006-
return await self.parse_response(connection, args[0], **kwargs)
1011+
return await self.parse_response(connection, *args, **kwargs)
1012+
except asyncio.CancelledError:
1013+
# should not be possible
1014+
await connection.disconnect(nowait=True)
1015+
raise
10071016
finally:
1008-
# Release connection
10091017
self._free.append(connection)
10101018

10111019
async def execute_pipeline(self, commands: List["PipelineCommand"]) -> bool:

0 commit comments

Comments
 (0)