From 5cea1e04d1e35882893b069ce297730299a0c003 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 16 Nov 2016 15:18:09 +0100 Subject: [PATCH] SSL disconnect fix - sometimes SSL connections unnecessarily disconnected on non-fatal errors. This should fix that. This is however a short term solution because of migrating to asyncore which has its own error handling --- src/class_receiveDataThread.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index df38f228..977250e0 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -90,9 +90,11 @@ class receiveDataThread(threading.Thread): shared.numberOfBytesReceivedLastSecond = 0 dataLen = len(self.data) try: + ssl = False if ((self.services & shared.NODE_SSL == shared.NODE_SSL) and self.connectionIsOrWasFullyEstablished and shared.haveSSL(not self.initiatedConnection)): + ssl = True dataRecv = self.sslSock.recv(1024) else: dataRecv = self.sock.recv(1024) @@ -103,8 +105,11 @@ class receiveDataThread(threading.Thread): logger.error ('Timeout occurred waiting for data from ' + str(self.peer) + '. Closing receiveData thread. (ID: ' + str(id(self)) + ')') break except Exception as err: - if (sys.platform == 'win32' and err.errno in ([2, 10035])) or (sys.platform != 'win32' and err.errno == errno.EWOULDBLOCK): - select.select([self.sslSock], [], []) + if err.errno == 2 or (sys.platform == 'win32' and err.errno == 10035) or (sys.platform != 'win32' and err.errno == errno.EWOULDBLOCK): + if ssl: + select.select([self.sslSock], [], []) + else: + select.select([self.sock], [], []) continue logger.error('sock.recv error. Closing receiveData thread (' + str(self.peer) + ', Thread ID: ' + str(id(self)) + ').' + str(err.errno) + "/" + str(err)) if self.initiatedConnection and not self.connectionIsOrWasFullyEstablished: