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

[tor-commits] [arm/master] fix: race condition between events and listeners



commit c73862469e55d361b1771e25efadaeacb9dc84aa
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jun 19 14:52:23 2011 -0700

    fix: race condition between events and listeners
    
    Status events have a small pause to colless events, but this caused a race
    when starting arm with the addition of status listeners. Dropping the sleep
    when handling our first signal.
---
 src/util/torTools.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index d1e5e9d..c44160e 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -105,6 +105,10 @@ PRIVATE_IP_RANGES = ("0.0.0.0/8", "169.254.0.0/16", "127.0.0.0/8", "192.168.0.0/
 
 NO_SPAWN = False
 
+# Flag to indicate if we're handling our first init signal. This is for
+# startup performance so we don't introduce a sleep while initializing.
+IS_STARTUP_SIGNAL = True
+
 def loadConfig(config):
   config.update(CONFIG)
 
@@ -2027,11 +2031,15 @@ class Controller(TorCtl.PostEventListener):
       eventType - enum representing tor's new status
     """
     
+    global IS_STARTUP_SIGNAL
+    
     # If there's a quick race state (for instance a sighup causing both an init
     # and close event) then give them a moment to enqueue. This way we can
     # coles the events and discard the inaccurate one.
     
-    time.sleep(0.2)
+    if not IS_STARTUP_SIGNAL:
+      time.sleep(0.2)
+    else: IS_STARTUP_SIGNAL = False
     
     self.connLock.acquire()
     



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits