Skip to content

Commit

Permalink
version 3.3.7, Fixed a socket.error regression introduced in 3.3.0
Browse files Browse the repository at this point in the history
Prior versions of 3.3.x could potentially raise a raw socket.error
(or one of its subclasses) instead of a redis.exceptions.ConnectionError.

Fixes #1202
  • Loading branch information
andymccurdy committed Aug 13, 2019
1 parent 038e5ee commit f0516c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 3.3.7
* Fixed a regression introduced in 3.3.0 where socket.error exceptions
(or subclasses) could potentially be raised instead of
redis.exceptions.ConnectionError. #1202
* 3.3.6
* Fixed a regression in 3.3.5 that caused PubSub.get_message() to raise
a socket.timeout exception when passing a timeout value. #1200
Expand Down
2 changes: 1 addition & 1 deletion redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def int_or_str(value):
return value


__version__ = '3.3.6'
__version__ = '3.3.7'
VERSION = tuple(map(int_or_str, __version__.split('.')))

__all__ = [
Expand Down
20 changes: 16 additions & 4 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
else:
NONBLOCKING_EXCEPTION_ERROR_NUMBERS[ssl.SSLError] = 2

# In Python 2.7 a socket.error is raised for a nonblocking read.
# The _compat module aliases BlockingIOError to socket.error to be
# Python 2/3 compatible.
# However this means that all socket.error exceptions need to be handled
# properly within these exception handlers.
# We need to make sure socket.error is included in these handlers and
# provide a dummy error number that will never match a real exception.
if socket.error not in NONBLOCKING_EXCEPTION_ERROR_NUMBERS:
NONBLOCKING_EXCEPTION_ERROR_NUMBERS[socket.error] = -999999

NONBLOCKING_EXCEPTIONS = tuple(NONBLOCKING_EXCEPTION_ERROR_NUMBERS.keys())

if HIREDIS_AVAILABLE:
Expand Down Expand Up @@ -184,7 +194,7 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
return True
except socket.timeout:
if raise_on_timeout:
raise
raise TimeoutError("Timeout reading from socket")
return False
except NONBLOCKING_EXCEPTIONS as ex:
# if we're in nonblocking mode and the recv raises a
Expand All @@ -194,7 +204,8 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
allowed = NONBLOCKING_EXCEPTION_ERROR_NUMBERS.get(ex.__class__, -1)
if not raise_on_timeout and ex.errno == allowed:
return False
raise
raise ConnectionError("Error while reading from socket: %s" %
(ex.args,))
finally:
if custom_timeout:
sock.settimeout(self.socket_timeout)
Expand Down Expand Up @@ -414,7 +425,7 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
return True
except socket.timeout:
if raise_on_timeout:
raise
raise TimeoutError("Timeout reading from socket")
return False
except NONBLOCKING_EXCEPTIONS as ex:
# if we're in nonblocking mode and the recv raises a
Expand All @@ -424,7 +435,8 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
allowed = NONBLOCKING_EXCEPTION_ERROR_NUMBERS.get(ex.__class__, -1)
if not raise_on_timeout and ex.errno == allowed:
return False
raise
raise ConnectionError("Error while reading from socket: %s" %
(ex.args,))
finally:
if custom_timeout:
sock.settimeout(self._socket_timeout)
Expand Down

0 comments on commit f0516c9

Please sign in to comment.