[or-cvs] r24113: {arm} Fixing the pesky syshook concurrency error that appears occa (in arm/trunk/src: interface util)

Damian Johnson atagar1 at gmail.com
Thu Jan 20 03:08:17 UTC 2011


Author: atagar
Date: 2011-01-20 03:08:16 +0000 (Thu, 20 Jan 2011)
New Revision: 24113

Modified:
   arm/trunk/src/interface/controller.py
   arm/trunk/src/util/torTools.py
Log:
Fixing the pesky syshook concurrency error that appears occasionally on shutdown.



Modified: arm/trunk/src/interface/controller.py
===================================================================
--- arm/trunk/src/interface/controller.py	2011-01-20 01:45:43 UTC (rev 24112)
+++ arm/trunk/src/interface/controller.py	2011-01-20 03:08:16 UTC (rev 24113)
@@ -808,6 +808,8 @@
         # this appears to be a python bug: http://bugs.python.org/issue3014
         # (haven't seen this is quite some time... mysteriously resolved?)
         
+        torTools.NO_SPAWN = True # prevents further worker threads from being spawned
+        
         # stops panel daemons
         panels["header"].stop()
         panels["log"].stop()

Modified: arm/trunk/src/util/torTools.py
===================================================================
--- arm/trunk/src/util/torTools.py	2011-01-20 01:45:43 UTC (rev 24112)
+++ arm/trunk/src/util/torTools.py	2011-01-20 03:08:16 UTC (rev 24113)
@@ -81,6 +81,12 @@
 # provides int -> str mappings for torctl event runlevels
 TORCTL_RUNLEVELS = dict([(val, key) for (key, val) in TorUtil.loglevels.items()])
 
+# This prevents controllers from spawning worker threads (and by extension
+# notifying status listeners). This is important when shutting down to prevent
+# rogue threads from being alive during shutdown.
+
+NO_SPAWN = False
+
 def loadConfig(config):
   config.update(CONFIG)
 
@@ -277,7 +283,8 @@
       self._statusTime = time.time()
       
       # notifies listeners that a new controller is available
-      thread.start_new_thread(self._notifyStatusListeners, (TOR_INIT,))
+      if not NO_SPAWN:
+        thread.start_new_thread(self._notifyStatusListeners, (TOR_INIT,))
   
   def close(self):
     """
@@ -287,6 +294,7 @@
     self.connLock.acquire()
     if self.conn:
       self.conn.close()
+      self.conn._thread.join()
       self.conn = None
       self.connLock.release()
       
@@ -294,7 +302,8 @@
       self._statusTime = time.time()
       
       # notifies listeners that the controller's been shut down
-      thread.start_new_thread(self._notifyStatusListeners, (TOR_CLOSED,))
+      if not NO_SPAWN:
+        thread.start_new_thread(self._notifyStatusListeners, (TOR_CLOSED,))
     else: self.connLock.release()
   
   def isAlive(self):
@@ -914,7 +923,8 @@
       self._status = TOR_INIT
       self._statusTime = time.time()
       
-      thread.start_new_thread(self._notifyStatusListeners, (TOR_INIT,))
+      if not NO_SPAWN:
+        thread.start_new_thread(self._notifyStatusListeners, (TOR_INIT,))
   
   def ns_event(self, event):
     self._updateHeartbeat()



More information about the tor-commits mailing list