andymccurdy/redis-py — pull request #465 by endophage (2014-04-24 23:01:29+00:00)
Title: Fix for socket hang when remote server disconnects

Fixes https://github.com/andymccurdy/redis-py/issues/386

According to this post, https://groups.google.com/d/msg/gevent/b8PrC-y9J6Y/lhKgKzuPl_cJ, on google groups, when socket.recv() returns an empty string it means the remote server has disconnected. The added lines simply check for this being the case and raise a socket.error if the empty string is returned. Raising the error appears to be the cleanest way to handle this as the existing code in place will then attempt to reconnect and bubble up a ConnectionError if the reconnect fails.