From e897c174483275fcb333e02bf36353a6afee44b4 Mon Sep 17 00:00:00 2001 From: Andy McCurdy Date: Mon, 29 Jul 2019 10:53:24 -0700 Subject: version 3.3.1, fixed a regression involving SSL and non-blocking sockets Fixes #1197 --- CHANGES | 3 +++ redis/__init__.py | 2 +- redis/connection.py | 27 +++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 18e9416..e46f1f6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +* 3.3.1 + * Fixed a regression introduced in 3.3.1 involving SSL and non-blocking + sockets. #1197 * 3.3.0 * Resolve a race condition with the PubSubWorkerThread. #1150 * Cleanup socket read error messages. Thanks Vic Yu. #1159 diff --git a/redis/__init__.py b/redis/__init__.py index cca895b..63b8d9d 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -29,7 +29,7 @@ def int_or_str(value): return value -__version__ = '3.3.0' +__version__ = '3.3.1' VERSION = tuple(map(int_or_str, __version__.split('.'))) __all__ = [ diff --git a/redis/connection.py b/redis/connection.py index b60a9fd..5ec2f2e 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -10,12 +10,6 @@ import sys import threading import warnings -try: - import ssl - ssl_available = True -except ImportError: - ssl_available = False - from redis._compat import (xrange, imap, byte_to_chr, unicode, long, nativestr, basestring, iteritems, LifoQueue, Empty, Full, urlparse, parse_qs, @@ -34,6 +28,23 @@ from redis.exceptions import ( TimeoutError, ) from redis.utils import HIREDIS_AVAILABLE + +try: + import ssl + ssl_available = True +except ImportError: + ssl_available = False + +if ssl_available: + blocking_exceptions = ( + BlockingIOError, + ssl.SSLWantReadError, + ssl.SSLWantWriteError + ) +else: + blocking_exceptions = (BlockingIOError,) + + if HIREDIS_AVAILABLE: import hiredis @@ -168,7 +179,7 @@ class SocketBuffer(object): if length is not None and length > marker: continue return True - except BlockingIOError as ex: + except blocking_exceptions as ex: # if we're in nonblocking mode and the recv raises a # blocking error, simply return False indicating that # there's no data to be read. otherwise raise the @@ -397,7 +408,7 @@ 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 BlockingIOError as ex: + except blocking_exceptions as ex: # if we're in nonblocking mode and the recv raises a # blocking error, simply return False indicating that # there's no data to be read. otherwise raise the -- cgit v1.2.1