From 7458b09e0742393a1ceb38e201e5730d551eb9f4 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 16 May 2013 13:10:40 -0400 Subject: [PATCH] Wrap all sock.shutdown functions in error handlers because evidently these can fail on some OSs if the socket is already shut down from earlier. --- src/bitmessagemain.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 5dbd6915..f3a341df 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -2051,8 +2051,11 @@ class sendDataThread(threading.Thread): shared.printLock.acquire() print 'sendDataThread (associated with', self.HOST,') ID:',id(self), 'shutting down now.' shared.printLock.release() - self.sock.shutdown(socket.SHUT_RDWR) - self.sock.close() + try: + self.sock.shutdown(socket.SHUT_RDWR) + self.sock.close() + except: + pass shared.sendDataQueues.remove(self.mailbox) shared.printLock.acquire() print 'len of sendDataQueues', len(shared.sendDataQueues) @@ -2087,8 +2090,11 @@ class sendDataThread(threading.Thread): self.lastTimeISentData = int(time.time()) except: print 'self.sock.sendall failed' - self.sock.shutdown(socket.SHUT_RDWR) - self.sock.close() + try: + self.sock.shutdown(socket.SHUT_RDWR) + self.sock.close() + except: + pass shared.sendDataQueues.remove(self.mailbox) print 'sendDataThread thread (ID:',str(id(self))+') ending now. Was connected to', self.HOST break @@ -2107,8 +2113,11 @@ class sendDataThread(threading.Thread): self.lastTimeISentData = int(time.time()) except: print 'self.sock.sendall failed' - self.sock.shutdown(socket.SHUT_RDWR) - self.sock.close() + try: + self.sock.shutdown(socket.SHUT_RDWR) + self.sock.close() + except: + pass shared.sendDataQueues.remove(self.mailbox) print 'sendDataThread thread (ID:',str(id(self))+') ending now. Was connected to', self.HOST break @@ -2123,8 +2132,11 @@ class sendDataThread(threading.Thread): self.lastTimeISentData = int(time.time()) except: print 'send pong failed' - self.sock.shutdown(socket.SHUT_RDWR) - self.sock.close() + try: + self.sock.shutdown(socket.SHUT_RDWR) + self.sock.close() + except: + pass shared.sendDataQueues.remove(self.mailbox) print 'sendDataThread thread', self, 'ending now. Was connected to', self.HOST break