From 17a8ece5c1bf976aeeb4d5865f818f3a96822e47 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 16 May 2013 12:41:04 -0400 Subject: [PATCH 1/3] Commit commands must be within a sqlLock --- src/bitmessageqt/__init__.py | 4 ++++ src/shared.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 2b68179f..86ac868f 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1744,7 +1744,9 @@ class MyForm(QtGui.QMainWindow): self.ui.textEditInboxMessage.setText("") self.ui.tableWidgetInbox.removeRow(currentRow) self.statusBar().showMessage('Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.') + shared.sqlLock.acquire() shared.sqlSubmitQueue.put('commit') + shared.sqlLock.release() if currentRow == 0: self.ui.tableWidgetInbox.selectRow(currentRow) else: @@ -1764,7 +1766,9 @@ class MyForm(QtGui.QMainWindow): self.ui.textEditSentMessage.setPlainText("") self.ui.tableWidgetSent.removeRow(currentRow) self.statusBar().showMessage('Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.') + shared.sqlLock.acquire() shared.sqlSubmitQueue.put('commit') + shared.sqlLock.release() if currentRow == 0: self.ui.tableWidgetSent.selectRow(currentRow) else: diff --git a/src/shared.py b/src/shared.py index ed1baf22..a5f635ea 100644 --- a/src/shared.py +++ b/src/shared.py @@ -167,11 +167,12 @@ def doCleanShutdown(): sqlSubmitQueue.put('SELECT address FROM subscriptions') sqlSubmitQueue.put('') sqlReturnQueue.get() + sqlSubmitQueue.put('exit') sqlLock.release() printLock.acquire() print 'Finished flushing inventory.' printLock.release() - sqlSubmitQueue.put('exit') + if safeConfigGetBoolean('bitmessagesettings','daemon'): printLock.acquire() -- 2.45.1 From dfd91d35af60bf9c26f2381959f703086499bb0d Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 16 May 2013 13:04:30 -0400 Subject: [PATCH 2/3] on exception during a SQL execute, show user the SQL line that caused the exception --- src/bitmessagemain.py | 10 +++++++++- src/bitmessageqt/__init__.py | 3 --- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index b51c73fc..5dbd6915 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -2446,7 +2446,15 @@ class sqlThread(threading.Thread): parameters = shared.sqlSubmitQueue.get() #print 'item', item #print 'parameters', parameters - self.cur.execute(item, parameters) + try: + self.cur.execute(item, parameters) + except Exception, err: + shared.printLock.acquire() + sys.stderr.write('\nMajor error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "'+str(item) + '" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: '+str(repr(parameters))+'\nHere is the actual error message thrown by the sqlThread: '+ str(err)+'\n') + sys.stderr.write('This program shall now abruptly exit!\n') + shared.printLock.release() + os._exit(0) + shared.sqlReturnQueue.put(self.cur.fetchall()) #shared.sqlSubmitQueue.task_done() diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 86ac868f..5233a532 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -230,9 +230,6 @@ class MyForm(QtGui.QMainWindow): if isEnabled: status,addressVersionNumber,streamNumber,hash = decodeAddress(addressInKeysFile) - #self.sqlLookup = sqlThread() - #self.sqlLookup.start() - self.ui.tableWidgetSent.keyPressEvent = self.tableWidgetSentKeyPressEvent font = QFont() font.setBold(True) -- 2.45.1 From 7458b09e0742393a1ceb38e201e5730d551eb9f4 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 16 May 2013 13:10:40 -0400 Subject: [PATCH 3/3] 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 -- 2.45.1