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.
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
index 3c7a3ca..eea5366 100644
--- a/lib/py/src/transport/TSocket.py
+++ b/lib/py/src/transport/TSocket.py
@@ -94,6 +94,9 @@
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 95124dc..b732653 100644
--- a/lib/py/test/test_socket.py
+++ b/lib/py/test/test_socket.py
@@ -25,6 +25,7 @@
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 f4c87f1..3b77e39 100644
--- a/lib/py/test/test_sslsocket.py
+++ b/lib/py/test/test_sslsocket.py
@@ -158,7 +158,9 @@
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)