Skip to content

Commit f0516c9

Browse files
committed
version 3.3.7, Fixed a socket.error regression introduced in 3.3.0
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 redis#1202
1 parent 038e5ee commit f0516c9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* 3.3.7
2+
* Fixed a regression introduced in 3.3.0 where socket.error exceptions
3+
(or subclasses) could potentially be raised instead of
4+
redis.exceptions.ConnectionError. #1202
15
* 3.3.6
26
* Fixed a regression in 3.3.5 that caused PubSub.get_message() to raise
37
a socket.timeout exception when passing a timeout value. #1200

redis/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def int_or_str(value):
2929
return value
3030

3131

32-
__version__ = '3.3.6'
32+
__version__ = '3.3.7'
3333
VERSION = tuple(map(int_or_str, __version__.split('.')))
3434

3535
__all__ = [

redis/connection.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
else:
4747
NONBLOCKING_EXCEPTION_ERROR_NUMBERS[ssl.SSLError] = 2
4848

49+
# In Python 2.7 a socket.error is raised for a nonblocking read.
50+
# The _compat module aliases BlockingIOError to socket.error to be
51+
# Python 2/3 compatible.
52+
# However this means that all socket.error exceptions need to be handled
53+
# properly within these exception handlers.
54+
# We need to make sure socket.error is included in these handlers and
55+
# provide a dummy error number that will never match a real exception.
56+
if socket.error not in NONBLOCKING_EXCEPTION_ERROR_NUMBERS:
57+
NONBLOCKING_EXCEPTION_ERROR_NUMBERS[socket.error] = -999999
58+
4959
NONBLOCKING_EXCEPTIONS = tuple(NONBLOCKING_EXCEPTION_ERROR_NUMBERS.keys())
5060

5161
if HIREDIS_AVAILABLE:
@@ -184,7 +194,7 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
184194
return True
185195
except socket.timeout:
186196
if raise_on_timeout:
187-
raise
197+
raise TimeoutError("Timeout reading from socket")
188198
return False
189199
except NONBLOCKING_EXCEPTIONS as ex:
190200
# if we're in nonblocking mode and the recv raises a
@@ -194,7 +204,8 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
194204
allowed = NONBLOCKING_EXCEPTION_ERROR_NUMBERS.get(ex.__class__, -1)
195205
if not raise_on_timeout and ex.errno == allowed:
196206
return False
197-
raise
207+
raise ConnectionError("Error while reading from socket: %s" %
208+
(ex.args,))
198209
finally:
199210
if custom_timeout:
200211
sock.settimeout(self.socket_timeout)
@@ -414,7 +425,7 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
414425
return True
415426
except socket.timeout:
416427
if raise_on_timeout:
417-
raise
428+
raise TimeoutError("Timeout reading from socket")
418429
return False
419430
except NONBLOCKING_EXCEPTIONS as ex:
420431
# if we're in nonblocking mode and the recv raises a
@@ -424,7 +435,8 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
424435
allowed = NONBLOCKING_EXCEPTION_ERROR_NUMBERS.get(ex.__class__, -1)
425436
if not raise_on_timeout and ex.errno == allowed:
426437
return False
427-
raise
438+
raise ConnectionError("Error while reading from socket: %s" %
439+
(ex.args,))
428440
finally:
429441
if custom_timeout:
430442
sock.settimeout(self._socket_timeout)

0 commit comments

Comments
 (0)