From 3ac67e5da7ddfe2d2f3579b1f5bea7b9231cddf5 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 9 Mar 2017 11:26:44 +0100 Subject: [PATCH] Connection error reporting changes - fewer tracebacks - more standardised reports including errno --- src/class_receiveDataThread.py | 10 +++++++--- src/class_sendDataThread.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index 90364228..124e06c0 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -123,11 +123,11 @@ class receiveDataThread(threading.Thread): select.select([self.sslSock if isSSL else self.sock], [], [], 10) logger.debug('sock.recv retriable error') continue - logger.error('sock.recv error. Closing receiveData thread (' + str(self.peer) + ', Thread ID: ' + str(id(self)) + ').' + str(err.errno) + "/" + str(err)) + logger.error('sock.recv error. Closing receiveData thread, %s', str(err)) break # print 'Received', repr(self.data) if len(self.data) == dataLen: # If self.sock.recv returned no data: - logger.debug('Connection to ' + str(self.peer) + ' closed. Closing receiveData thread. (ID: ' + str(id(self)) + ')') + logger.debug('Connection to ' + str(self.peer) + ' closed. Closing receiveData thread') break else: self.processData() @@ -302,9 +302,13 @@ class receiveDataThread(threading.Thread): logger.debug("Waiting for SSL socket handhake write") select.select([], [self.sslSock], [], 10) continue - logger.error("SSL socket handhake failed: %s, shutting down connection", str(e)) + logger.error("SSL socket handhake failed: shutting down connection, %s", str(e)) self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail %s' % (str(e)))) return False + except socket.error as err: + logger.debug('SSL socket handshake failed, shutting down connection, %s', str(err)) + self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail')) + return False except Exception: logger.error("SSL socket handhake failed, shutting down connection", exc_info=True) self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail')) diff --git a/src/class_sendDataThread.py b/src/class_sendDataThread.py index 7de63a02..ac11c6b2 100644 --- a/src/class_sendDataThread.py +++ b/src/class_sendDataThread.py @@ -105,8 +105,8 @@ class sendDataThread(threading.Thread): select.select([], [self.sslSock if isSSL else self.sock], [], 10) logger.debug('sock.recv retriable error') continue - if e.errno in (errno.EPIPE, errno.ECONNRESET, errno.EHOSTUNREACH, errno.ETIMEDOUT): - logger.debug('Connection error (EPIPE/ECONNRESET/EHOSTUNREACH/ETIMEDOUT)') + if e.errno in (errno.EPIPE, errno.ECONNRESET, errno.EHOSTUNREACH, errno.ETIMEDOUT, errno.ECONNREFUSED): + logger.debug('Connection error: %s', str(e)) return False raise throttle.SendThrottle().wait(amountSent)