[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Move acquire-lock operations out of try-finally blocks ...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv21619/lib/mixminion

Modified Files:
	ClientDirectory.py ClientMain.py 
Log Message:
Move acquire-lock operations out of try-finally blocks to help debug possible exceptions [may help find bug 29]

Index: ClientDirectory.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientDirectory.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- ClientDirectory.py	23 Mar 2004 00:35:07 -0000	1.36
+++ ClientDirectory.py	23 Mar 2004 03:54:12 -0000	1.37
@@ -110,8 +110,9 @@
             self._diskLock = threading.RLock()
         else:
             self._diskLock = diskLock
+
+        self._diskLock.acquire()
         try:
-            self._diskLock.acquire()
             self.__load()
             self.clean()
         finally:
@@ -236,17 +237,19 @@
         if fp and mixminion.Crypto.pk_fingerprint(identity) != fp:
             raise MixFatalError("Bad identity key on directory")
 
+        self._lock.write_in()
         try:
-            self._lock.write_in()
             self._diskLock.acquire()
-            # Install the new directory
-            tryUnlink(os.path.join(self.dir, "cache"))
-            if gz:
-                replaceFile(fname, os.path.join(self.dir, "dir.gz"))
-            else:
-                replaceFile(fname, os.path.join(self.dir, "dir"))
+            try:
+                # Install the new directory
+                tryUnlink(os.path.join(self.dir, "cache"))
+                if gz:
+                    replaceFile(fname, os.path.join(self.dir, "dir.gz"))
+                else:
+                    replaceFile(fname, os.path.join(self.dir, "dir"))
+            finally:
+                self._diskLock.release()
         finally:
-            self._diskLock.release()
             self._lock.write_out()
 
         # And regenerate the cache.
@@ -278,7 +281,7 @@
         dirFile = os.path.join(self.dir, "dir")
         for fname in gzipFile, dirFile:
             self._diskLock.acquire()
-            if not os.path.exists(fname): 
+            if not os.path.exists(fname):
                 self._diskLock.release()
                 continue
             try:

Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- ClientMain.py	23 Mar 2004 03:03:36 -0000	1.171
+++ ClientMain.py	23 Mar 2004 03:54:12 -0000	1.172
@@ -493,8 +493,8 @@
         nGood = len(packetsSentByIndex)
         nBad = len(pktList)-nGood
 
+        clientLock()
         try:
-            clientLock()
             if nGood:
                 LOG.info("... %s sent", nGood)
                 LOG.trace("Removing %s successful packets from queue", nGood)
@@ -533,7 +533,7 @@
             if exc:
                 LOG.info("Error was: %s", exc[1])
         finally:
-                clientUnlock()
+            clientUnlock()
 
         return nGood
 
@@ -603,8 +603,8 @@
     def cleanQueue(self, handles):
         """Remove all packets older than maxAge seconds from the
            client queue."""
+        clientLock()
         try:
-            clientLock()
             byRouting = self._sortPackets(
                 [ (h, self.queue.getRouting(h)) for h in handles ],
                 shuffle = 0)
@@ -629,8 +629,8 @@
         #XXXX write unit tests
         LOG.trace("Queueing packets")
         handles = []
+        clientLock()
         try:
-            clientLock()
             for pkt in pktList:
                 h = self.queue.queuePacket(str(pkt), routing)
                 handles.append(h)
@@ -957,8 +957,8 @@
             assert self.wantClientDirectory
             timeout = int(self.config['DirectoryServers']['DirectoryTimeout'])
             if self.download != 0:
+                clientLock()
                 try:
-                    clientLock()
                     self.directory.updateDirectory(forceDownload=self.download,
                                                    timeout=timeout)
                 finally:
@@ -1340,8 +1340,8 @@
     parser.init()
     directory = parser.directory
 
+    clientLock()
     try:
-        clientLock()
         for filename in args:
             print "Importing from", filename
             try:
@@ -1519,8 +1519,8 @@
     directory = parser.directory
     config = parser.config
     timeout = int(config['DirectoryServers']['DirectoryTimeout'])
+    clientLock()
     try:
-        clientLock()
         directory.updateDirectory(forceDownload=1, timeout=timeout)
     finally:
         clientUnlock()
@@ -1883,8 +1883,8 @@
     parser.init()
     client = parser.client
 
+    clientLock()
     try:
-        clientLock()
         res = client.queue.inspectQueue()
     finally:
         clientUnlock()
@@ -1931,8 +1931,8 @@
     parser.init()
     client = parser.client
 
+    clientLock()
     try:
-        clientLock()
         res = client.pool.formatMessageList()
     finally:
         clientUnlock()
@@ -1994,8 +1994,8 @@
             out = open(outfilename, 'wb')
             closeoutfile = 1
 
+    clientLock()
     try:
-        clientLock()
         removed = []
         for msgid in args:
             if reassemble:
@@ -2006,6 +2006,6 @@
         if reassemble:
             out.write(msg)
     finally:
-        clientUnlock()
         if reassemble and closeoutfile:
             out.close()
+        clientUnlock()