Skip to content

Commit a5ba696

Browse files
committed
version 3.3.5, handle socket.timeout errors correctly in Python 2.7
Fix an issue where socket.timeout errors could be handled by the wrong exception handler in Python 2.7.
1 parent 3afa016 commit a5ba696

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* 3.3.5
2+
* Fix an issue where socket.timeout errors could be handled by the wrong
3+
exception handler in Python 2.7.
14
* 3.3.4
25
* More specifically identify nonblocking read errors for both SSL and
36
non-SSL connections. 3.3.1, 3.3.2 and 3.3.3 on Python 2.7 could

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.4'
32+
__version__ = '3.3.5'
3333
VERSION = tuple(map(int_or_str, __version__.split('.')))
3434

3535
__all__ = [

redis/connection.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,10 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
187187
# blocking error, simply return False indicating that
188188
# there's no data to be read. otherwise raise the
189189
# original exception.
190-
allowed_errno = NONBLOCKING_EXCEPTION_ERROR_NUMBERS[ex.__class__]
191-
if raise_on_timeout or ex.errno != allowed_errno:
192-
raise
193-
return False
194-
except socket.timeout:
195-
if raise_on_timeout:
196-
raise
197-
return False
190+
allowed = NONBLOCKING_EXCEPTION_ERROR_NUMBERS.get(ex.__class__, -1)
191+
if not raise_on_timeout and ex.errno == allowed:
192+
return False
193+
raise
198194
finally:
199195
if custom_timeout:
200196
sock.settimeout(self.socket_timeout)
@@ -417,14 +413,10 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
417413
# blocking error, simply return False indicating that
418414
# there's no data to be read. otherwise raise the
419415
# original exception.
420-
allowed_errno = NONBLOCKING_EXCEPTION_ERROR_NUMBERS[ex.__class__]
421-
if raise_on_timeout or ex.errno != allowed_errno:
422-
raise
423-
return False
424-
except socket.timeout:
425-
if not raise_on_timeout:
426-
raise
427-
return False
416+
allowed = NONBLOCKING_EXCEPTION_ERROR_NUMBERS.get(ex.__class__, -1)
417+
if not raise_on_timeout and ex.errno == allowed:
418+
return False
419+
raise
428420
finally:
429421
if custom_timeout:
430422
sock.settimeout(self._socket_timeout)

0 commit comments

Comments
 (0)