summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Smith <michael.smith@cloudera.com>2022-06-08 17:23:27 -0700
committerYuxuan 'fishy' Wang <fishywang@gmail.com>2022-06-10 08:41:25 -0700
commite3eb9afb20a0535d44c203a4195db9822f8861fc (patch)
tree22449e217b4ca184342dbc6e562cdd3db2fea45b
parent4959a92385e2a6d7a4b8419784f85e5762c714cf (diff)
downloadthrift-e3eb9afb20a0535d44c203a4195db9822f8861fc.tar.gz
THRIFT-5595: Handle peek request error with SSLSocket
The update to TSocket in 01d53f483a7531ad4899b522060e8913dca309fb errors for TSSLSocket with ``` ValueError: non-zero flags not allowed in calls to recv() on <class 'ssl.SSLSocket'> ``` Handles ValueError from ssl.SSLSocket to fix isOpen when using TSSLSocket.
-rw-r--r--lib/py/src/transport/TSocket.py3
-rw-r--r--lib/py/test/test_socket.py1
-rw-r--r--lib/py/test/test_sslsocket.py2
3 files changed, 6 insertions, 0 deletions
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
index 3c7a3ca7d..eea5366c7 100644
--- a/lib/py/src/transport/TSocket.py
+++ b/lib/py/src/transport/TSocket.py
@@ -94,6 +94,9 @@ class TSocket(TSocketBase):
if exc.errno in (errno.EWOULDBLOCK, errno.EAGAIN):
return True
return False
+ except ValueError:
+ # SSLSocket fails on recv with non-zero flags; fallback to the old behavior
+ return True
finally:
self.handle.settimeout(original_timeout)
diff --git a/lib/py/test/test_socket.py b/lib/py/test/test_socket.py
index 95124dcbe..b732653a4 100644
--- a/lib/py/test/test_socket.py
+++ b/lib/py/test/test_socket.py
@@ -25,6 +25,7 @@ class TSocketTest(unittest.TestCase):
acc.start()
sock = TSocket(host="localhost", port=acc.port)
+ self.assertFalse(sock.isOpen())
sock.open()
sock.setTimeout(timeout)
diff --git a/lib/py/test/test_sslsocket.py b/lib/py/test/test_sslsocket.py
index f4c87f195..3b77e391b 100644
--- a/lib/py/test/test_sslsocket.py
+++ b/lib/py/test/test_sslsocket.py
@@ -158,7 +158,9 @@ class TSSLSocketTest(unittest.TestCase):
def _assert_connection_success(self, server, path=None, **client_args):
with self._connectable_client(server, path=path, **client_args) as (acc, client):
try:
+ self.assertFalse(client.isOpen())
client.open()
+ self.assertTrue(client.isOpen())
client.write(b"hello")
self.assertEqual(client.read(5), b"there")
self.assertTrue(acc.client is not None)