From 038e5ee019ecaa29b073a89e61585d404579beff Mon Sep 17 00:00:00 2001 From: Andy McCurdy Date: Tue, 6 Aug 2019 10:59:38 -0700 Subject: version 3.3.6, fixed a regression in 3.3.5 with pubsub timeouts Fixes #1200 --- CHANGES | 3 +++ redis/__init__.py | 2 +- redis/connection.py | 8 ++++++++ tests/test_pubsub.py | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index fd58905..cc61dad 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +* 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 * 3.3.5 * Fix an issue where socket.timeout errors could be handled by the wrong exception handler in Python 2.7. diff --git a/redis/__init__.py b/redis/__init__.py index 66ef979..6200d4d 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -29,7 +29,7 @@ def int_or_str(value): return value -__version__ = '3.3.5' +__version__ = '3.3.6' VERSION = tuple(map(int_or_str, __version__.split('.'))) __all__ = [ diff --git a/redis/connection.py b/redis/connection.py index 151d4d0..3a0ae65 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -182,6 +182,10 @@ class SocketBuffer(object): if length is not None and length > marker: continue return True + except socket.timeout: + if raise_on_timeout: + raise + return False except NONBLOCKING_EXCEPTIONS as ex: # if we're in nonblocking mode and the recv raises a # blocking error, simply return False indicating that @@ -408,6 +412,10 @@ class HiredisParser(BaseParser): # data was read from the socket and added to the buffer. # return True to indicate that data was read. return True + except socket.timeout: + if raise_on_timeout: + raise + return False except NONBLOCKING_EXCEPTIONS as ex: # if we're in nonblocking mode and the recv raises a # blocking error, simply return False indicating that diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py index fee04da..2644d60 100644 --- a/tests/test_pubsub.py +++ b/tests/test_pubsub.py @@ -531,3 +531,11 @@ class TestPubSubConnectionKilled(object): r.client_kill_filter(_id=client['id']) with pytest.raises(ConnectionError): wait_for_message(p) + + +class TestPubSubTimeouts(object): + def test_get_message_with_timeout_returns_none(self, r): + p = r.pubsub() + p.subscribe('foo') + assert wait_for_message(p) == make_message('subscribe', 'foo', 1) + assert p.get_message(timeout=0.01) is None -- cgit v1.2.1