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

[tor-commits] [flashproxy/master] Fix a race condition in registration.



commit 5cea698be4f714cae7c660ae46bd55aa3ee0a133
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Tue Jul 30 22:56:10 2013 -0700

    Fix a race condition in registration.
    
    This could cause the first registration message not to be sent. The
    registration thread used the "notify" of a condition variable as the
    signal to do a registration. If the main thread did its "notify" before
    the registration thread did its "wait", then the registration thread
    would not wake up until the next time a registration was requested.
---
 flashproxy-client |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/flashproxy-client b/flashproxy-client
index 89eda2a..cf16437 100755
--- a/flashproxy-client
+++ b/flashproxy-client
@@ -730,10 +730,15 @@ def forward_ports(pairs):
     return True
  
 register_condvar = threading.Condition()
+# register_flag true means registration_thread_func should register at its next
+# opportunity.
+register_flag = False
 def register():
+    global register_flag
     if not options.register:
         return
     register_condvar.acquire()
+    register_flag = True
     register_condvar.notify()
     register_condvar.release()
 
@@ -765,9 +770,12 @@ def register_one():
         log(u"All registration commands failed.")
 
 def registration_thread_func():
+    global register_flag
     while True:
         register_condvar.acquire()
-        register_condvar.wait()
+        while not register_flag:
+            register_condvar.wait()
+        register_flag = False
         register_condvar.release()
         if len(unlinked_remotes) < DESIRED_NUMBER_OF_PROXIES:
             register_one()

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