[or-cvs] r22319: {arm} fix: concurrency bug when halting connection resolvers (arm/trunk/util)

Damian Johnson atagar1 at gmail.com
Wed May 12 14:58:18 UTC 2010


Author: atagar
Date: 2010-05-12 14:58:18 +0000 (Wed, 12 May 2010)
New Revision: 22319

Modified:
   arm/trunk/util/connections.py
   arm/trunk/util/sysTools.py
Log:
fix: concurrency bug when halting connection resolvers



Modified: arm/trunk/util/connections.py
===================================================================
--- arm/trunk/util/connections.py	2010-05-12 04:25:47 UTC (rev 22318)
+++ arm/trunk/util/connections.py	2010-05-12 14:58:18 UTC (rev 22319)
@@ -104,7 +104,7 @@
   """
   
   for resolver in RESOLVERS:
-    if resolver.processName == processName and (not processPid or resolver.processPid == processPid):
+    if not resolver._halt and resolver.processName == processName and (not processPid or resolver.processPid == processPid):
       return True
   
   return False
@@ -121,14 +121,20 @@
   """
   
   # check if one's already been created
-  for resolver in RESOLVERS:
+  haltedIndex = -1 # old instance of this resolver with the _halt flag set
+  for i in range(len(RESOLVERS)):
+    resolver = RESOLVERS[i]
     if resolver.processName == processName and (not processPid or resolver.processPid == processPid):
-      return resolver
+      if resolver._halt: haltedIndex = i
+      else: return resolver
   
   # make a new resolver
   r = ConnectionResolver(processName, processPid)
   r.start()
-  RESOLVERS.append(r)
+  
+  # overwrites halted instance of this resolver if it exists, otherwise append
+  if haltedIndex == -1: RESOLVERS.append(r)
+  else: RESOLVERS[haltedIndex] = r
   return r
 
 if __name__ == '__main__':
@@ -326,7 +332,4 @@
     """
     
     self._halt = True
-    
-    # removes this from consideration among active singleton instances
-    if self in RESOLVERS: RESOLVERS.remove(self)
 

Modified: arm/trunk/util/sysTools.py
===================================================================
--- arm/trunk/util/sysTools.py	2010-05-12 04:25:47 UTC (rev 22318)
+++ arm/trunk/util/sysTools.py	2010-05-12 14:58:18 UTC (rev 22319)
@@ -112,11 +112,11 @@
         log.log(log.DEBUG, "system call (cached): %s (age: %0.1f seconds)" % (command, cacheAge))
         return cachedResults
   
-  # preprocessing for the commands to prevent anything going to stdout
   startTime = time.time()
   commandComp = command.split("|")
   commandCall, results, errorExc = None, None, None
   
+  # preprocessing for the commands to prevent anything going to stdout
   for i in range(len(commandComp)):
     subcommand = commandComp[i].strip()
     



More information about the tor-commits mailing list