Skip to content

Commit

Permalink
version 3.3.6, fixed a regression in 3.3.5 with pubsub timeouts
Browse files Browse the repository at this point in the history
Fixes #1200
  • Loading branch information
andymccurdy committed Aug 6, 2019
1 parent a5ba696 commit 038e5ee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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.
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.5'
__version__ = '3.3.6'
VERSION = tuple(map(int_or_str, __version__.split('.')))

__all__ = [
Expand Down
8 changes: 8 additions & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def _read_from_socket(self, length=None, timeout=SENTINEL,
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
Expand Down Expand Up @@ -408,6 +412,10 @@ def read_from_socket(self, timeout=SENTINEL, raise_on_timeout=True):
# 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
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,11 @@ def test_connection_error_raised_when_connection_dies(self, r):
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

0 comments on commit 038e5ee

Please sign in to comment.