summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Mueller <dmueller@suse.com>2019-01-31 15:07:26 +0100
committerMatus Valo <matusvalo@users.noreply.github.com>2019-01-31 15:07:26 +0100
commitbf122a05a21a8cc5bca314b0979f32c8026fc66e (patch)
tree0bf85800cd29ff26ac8b5dc131f1e9e2cb17d83f
parent457b3bad961cc7ad64466ad18909650dd648d749 (diff)
downloadpy-amqp-bf122a05a21a8cc5bca314b0979f32c8026fc66e.tar.gz
Always treat SSLError timeouts as socket timeouts (#247)
Without specifically handling this case, the socket.timeout() was not raised sometimes causing the connection to lock up. In the case we hit the errno was None, so the previous if condition did not apply. Co-Authored-By: aojeagarcia <aojeagarcia@suse.com>
-rw-r--r--amqp/transport.py4
-rw-r--r--t/unit/test_transport.py18
2 files changed, 21 insertions, 1 deletions
diff --git a/amqp/transport.py b/amqp/transport.py
index ea713fd..898dbe6 100644
--- a/amqp/transport.py
+++ b/amqp/transport.py
@@ -376,6 +376,10 @@ class SSLTransport(_AbstractTransport):
try:
s = recv(n - len(rbuf)) # see note above
except socket.error as exc:
+ # ssl.sock.read may cause a SSLerror without errno
+ # http://bugs.python.org/issue10272
+ if isinstance(exc, SSLError) and 'timed out' in str(exc):
+ raise socket.timeout()
# ssl.sock.read may cause ENOENT if the
# operation couldn't be performed (Issue celery#1414).
if exc.errno in _errnos:
diff --git a/t/unit/test_transport.py b/t/unit/test_transport.py
index 10a112b..dfc398c 100644
--- a/t/unit/test_transport.py
+++ b/t/unit/test_transport.py
@@ -5,7 +5,7 @@ import socket
import struct
import pytest
-from case import ANY, Mock, call, patch
+from case import ANY, Mock, MagicMock, call, patch
from amqp import transport
from amqp.exceptions import UnexpectedFrame
@@ -653,6 +653,22 @@ class test_SSLTransport:
match=r'.*Socket closed.*'):
self.t._write('foo')
+ def test_read_timeout(self):
+ self.t.sock = Mock(name='SSLSocket')
+ self.t._quick_recv = Mock(name='recv', return_value='4')
+ self.t._quick_recv.side_effect = socket.timeout()
+ self.t._read_buffer = MagicMock(return_value='AA')
+ with pytest.raises(socket.timeout):
+ self.t._read(64)
+
+ def test_read_SSLError(self):
+ self.t.sock = Mock(name='SSLSocket')
+ self.t._quick_recv = Mock(name='recv', return_value='4')
+ self.t._quick_recv.side_effect = transport.SSLError('timed out')
+ self.t._read_buffer = MagicMock(return_value='AA')
+ with pytest.raises(socket.timeout):
+ self.t._read(64)
+
class test_TCPTransport: