Skip to content

Commit 12fbc7d

Browse files
Fix unrecoverable connection state (#3905)
* Fix unrecoverable connection state * Raise OSError instead * Also raise OSError in can_read_destructive() in _AsyncHiredisParser * Raise ConnectionError in on_connect() --------- Co-authored-by: petyaslavova <petya.slavova@redis.com>
1 parent 7081047 commit 12fbc7d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

redis/_parsers/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
NoScriptError,
3636
OutOfMemoryError,
3737
ReadOnlyError,
38-
RedisError,
3938
ResponseError,
4039
TryAgainError,
4140
)
@@ -415,7 +414,7 @@ def on_connect(self, connection):
415414
"""Called when the stream connects"""
416415
self._stream = connection._reader
417416
if self._stream is None:
418-
raise RedisError("Buffer is closed.")
417+
raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
419418
self.encoder = connection.encoder
420419
self._clear()
421420
self._connected = True
@@ -426,7 +425,7 @@ def on_disconnect(self):
426425

427426
async def can_read_destructive(self) -> bool:
428427
if not self._connected:
429-
raise RedisError("Buffer is closed.")
428+
raise OSError("Buffer is closed.")
430429
if self._buffer:
431430
return True
432431
try:

redis/_parsers/hiredis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def on_disconnect(self):
238238

239239
async def can_read_destructive(self):
240240
if not self._connected:
241-
raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
241+
raise OSError("Buffer is closed.")
242242
if self._reader.gets() is not NOT_ENOUGH_DATA:
243243
return True
244244
try:

0 commit comments

Comments
 (0)