From b1b0c46555f52ce343d0b83cdd9e792164d714c6 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 26 Feb 2017 12:42:18 +0100 Subject: [PATCH] Improve exception handling - there were reports of errors in FreeBSD (I could only reproduce some) and Gentoo without IPv4 support (I don't have a VM for testing ready) - adds an exception handler for double task_done in case sender thread has to close prematurely (I saw this triggered on FreeBSD 11) - listening socket opening error handler was broken (triggered if you can't open a socket with both IPv4 and IPv6 support) - error handler for socket.accept. Reported on FreeBSD 10.3 - fixes #854 --- src/class_sendDataThread.py | 6 +++++- src/class_singleListener.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/class_sendDataThread.py b/src/class_sendDataThread.py index 3d35c48a..552cbffc 100644 --- a/src/class_sendDataThread.py +++ b/src/class_sendDataThread.py @@ -201,7 +201,11 @@ class sendDataThread(threading.Thread): elif self.connectionIsOrWasFullyEstablished: logger.error('sendDataThread ID: ' + str(id(self)) + ' ignoring command ' + command + ' because the thread is not in stream ' + str(deststream) + ' but in streams ' + ', '.join(str(x) for x in self.streamNumber)) self.sendDataThreadQueue.task_done() - self.sendDataThreadQueue.task_done() + # Flush if the cycle ended with break + try: + self.sendDataThreadQueue.task_done() + except ValueError + pass try: self.sock.shutdown(socket.SHUT_RDWR) diff --git a/src/class_singleListener.py b/src/class_singleListener.py index 0a8c4a93..f41a9724 100644 --- a/src/class_singleListener.py +++ b/src/class_singleListener.py @@ -86,7 +86,7 @@ class singleListener(threading.Thread, StoppableThread): # we'll fall back to IPv4-only. try: sock = self._createListenSocket(socket.AF_INET6) - except socket.error, e: + except socket.error as e: if (isinstance(e.args, tuple) and e.args[0] in (errno.EAFNOSUPPORT, errno.EPFNOSUPPORT, @@ -112,7 +112,15 @@ class singleListener(threading.Thread, StoppableThread): self.stop.wait(10) while state.shutdown == 0: - socketObject, sockaddr = sock.accept() + try: + socketObject, sockaddr = sock.accept() + except socket.error as e: + if isinstance(e.args, tuple) and + e.args[0] in (errno.EINTR,): + continue + time.wait(1) + continue + (HOST, PORT) = sockaddr[0:2] # If the address is an IPv4-mapped IPv6 address then