Skip to content

Commit

Permalink
don't use can_read in pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Sep 19, 2022
1 parent edc57a4 commit 4e7a402
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions redis/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
cast,
)

import async_timeout

from redis.asyncio.connection import (
Connection,
ConnectionPool,
Expand Down Expand Up @@ -755,12 +757,16 @@ async def parse_response(self, block: bool = True, timeout: float = 0):
await self.check_health()

async def try_read():
if not conn.is_connected:
await conn.connect()
if not block:
if not await conn.can_read(timeout=timeout):
try:
async with async_timeout.timeout(timeout):
return await conn.read_response()
except asyncio.TimeoutError:
return None
else:
await conn.connect()
return await conn.read_response()
return await conn.read_response()

response = await self._execute(conn, try_read)

Expand Down
6 changes: 5 additions & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,11 @@ async def read_response(self, disable_decoding: bool = False):
raise ConnectionError(
f"Error while reading from {self.host}:{self.port} : {e.args}"
)
except BaseException:
except asyncio.CancelledError:
# need this check for 3.7, where CancelledError
# is subclass of Exception, not BaseException
raise
except Exception:
await self.disconnect()
raise

Expand Down

0 comments on commit 4e7a402

Please sign in to comment.