[or-cvs] r19577: {torflow} Add timer to work around Tor exit node stream hang bug. (in torflow/trunk/NetworkScanners/BwAuthority: . scanner.1)

mikeperry at seul.org mikeperry at seul.org
Thu May 28 12:21:01 UTC 2009


Author: mikeperry
Date: 2009-05-28 08:21:01 -0400 (Thu, 28 May 2009)
New Revision: 19577

Modified:
   torflow/trunk/NetworkScanners/BwAuthority/bwauthority.py
   torflow/trunk/NetworkScanners/BwAuthority/scanner.1/bwauthority.cfg
Log:

Add timer to work around Tor exit node stream hang bug.



Modified: torflow/trunk/NetworkScanners/BwAuthority/bwauthority.py
===================================================================
--- torflow/trunk/NetworkScanners/BwAuthority/bwauthority.py	2009-05-28 11:50:55 UTC (rev 19576)
+++ torflow/trunk/NetworkScanners/BwAuthority/bwauthority.py	2009-05-28 12:21:01 UTC (rev 19577)
@@ -67,8 +67,10 @@
   save_every = config.getint('BwAuthority', 'save_every')
   circs_per_node = config.getint('BwAuthority', 'circs_per_node')
   out_dir = config.get('BwAuthority', 'out_dir')
+  max_fetch_time = config.getint('BwAuthority', 'max_fetch_time')
 
-  return (start_pct,stop_pct,nodes_per_slice,save_every,circs_per_node,out_dir)
+  return (start_pct,stop_pct,nodes_per_slice,save_every,
+            circs_per_node,out_dir,max_fetch_time)
 
 def choose_url(percentile):
   for (pct, url) in urls:
@@ -170,6 +172,18 @@
     cond.wait()
     cond.release()
 
+  def close_streams(self, reason):
+    cond = threading.Condition()
+    def notlambda(this):
+      cond.acquire()
+      this.close_all_streams(reason)
+      cond.notify()
+      cond.release()
+    cond.acquire()
+    self.schedule_low_prio(notlambda)
+    cond.wait()
+    cond.release()
+
   def new_exit(self):
     cond = threading.Condition()
     def notlambda(this):
@@ -254,7 +268,8 @@
     traceback.print_exc()
     return 0 
 
-def speedrace(hdlr, start_pct, stop_pct, circs_per_node, save_every, out_dir):
+def speedrace(hdlr, start_pct, stop_pct, circs_per_node, save_every, out_dir, 
+              max_fetch_time):
   hdlr.set_pct_rstr(start_pct, stop_pct)
 
   attempt = 0
@@ -265,10 +280,16 @@
     attempt += 1
     
     t0 = time()
+    # XXX: This noise is due to a difficult to find Tor bug that
+    # causes some exits to hang forever on streams :(
+    timer = threading.Timer(max_fetch_time, lambda: hdlr.close_streams(7))
+    timer.start()
     ret = http_request(choose_url(start_pct))
+    timer.cancel()
+
     delta_build = time() - t0
-    if delta_build >= 550.0:
-      plog('NOTICE', 'Timer exceeded limit: ' + str(delta_build) + '\n')
+    if delta_build >= max_fetch_time:
+      plog('WARN', 'Timer exceeded limit: ' + str(delta_build) + '\n')
 
     build_exit = hdlr.get_exit_node()
     if ret == 1:
@@ -291,7 +312,7 @@
 def main(argv):
   TorUtil.read_config(argv[1]) 
   (start_pct,stop_pct,nodes_per_slice,save_every,
-         circs_per_node,out_dir) = read_config(argv[1])
+         circs_per_node,out_dir,max_fetch_time) = read_config(argv[1])
  
   try:
     (c,hdlr) = setup_handler()
@@ -315,7 +336,8 @@
       hdlr.commit()
       plog('DEBUG', 'Reset stats')
 
-      speedrace(hdlr, pct, pct+pct_step, circs_per_node, save_every, out_dir)
+      speedrace(hdlr, pct, pct+pct_step, circs_per_node, save_every, out_dir,
+                max_fetch_time)
 
       plog('DEBUG', 'speedroced')
       hdlr.commit()

Modified: torflow/trunk/NetworkScanners/BwAuthority/scanner.1/bwauthority.cfg
===================================================================
--- torflow/trunk/NetworkScanners/BwAuthority/scanner.1/bwauthority.cfg	2009-05-28 11:50:55 UTC (rev 19576)
+++ torflow/trunk/NetworkScanners/BwAuthority/scanner.1/bwauthority.cfg	2009-05-28 12:21:01 UTC (rev 19577)
@@ -15,4 +15,5 @@
 stop_pct = 15
 save_every = 10
 nodes_per_slice = 50
-circs_per_node = 7
+circs_per_node = 2
+max_fetch_time = 1800



More information about the tor-commits mailing list