[or-cvs] backport the hack to cull wedged cpuworkers

Roger Dingledine arma at seul.org
Thu Apr 7 21:23:12 UTC 2005


Update of /home2/or/cvsroot/tor/src/or
In directory moria.mit.edu:/home2/arma/work/onion/0091/tor/src/or

Modified Files:
      Tag: tor-0_0_9-patches
	cpuworker.c 
Log Message:
backport the hack to cull wedged cpuworkers


Index: cpuworker.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/cpuworker.c,v
retrieving revision 1.61.2.2
retrieving revision 1.61.2.3
diff -u -d -r1.61.2.2 -r1.61.2.3
--- cpuworker.c	28 Jan 2005 09:59:23 -0000	1.61.2.2
+++ cpuworker.c	7 Apr 2005 21:23:10 -0000	1.61.2.3
@@ -347,6 +347,34 @@
     log_fn(LOG_WARN,"assign_to_cpuworker failed. Ignoring.");
 }
 
+#define CPUWORKER_BUSY_TIMEOUT 100 /* seconds */
+
+/** We have a bug that I can't find. Sometimes, very rarely, cpuworkers
+ * get stuck in the 'busy' state, even though the cpuworker process
+ * thinks of itself as idle. I don't know why. But here's a workaround
+ * to kill any cpuworker that's been busy for more than 100 seconds. */
+static void
+cull_wedged_cpuworkers(void) {
+  connection_t **carray;
+  connection_t *conn;
+  int n_conns, i;
+  time_t now = time(NULL);
+
+  get_connection_array(&carray, &n_conns);
+  for (i = 0; i < n_conns; ++i) {
+    conn = carray[i];
+    if (!conn->marked_for_close &&
+        conn->type == CONN_TYPE_CPUWORKER &&
+        conn->state == CPUWORKER_STATE_BUSY_ONION &&
+        conn->timestamp_lastwritten + CPUWORKER_BUSY_TIMEOUT > now) {
+      log_fn(LOG_NOTICE,"Bug: closing wedged cpuworker. Can somebody find the bug?");
+      num_cpuworkers_busy--;
+      num_cpuworkers--;
+      connection_mark_for_close(conn);
+    }
+  }
+}
+
 /** if cpuworker is defined, assert that he's idle, and use him. else,
  * look for an idle cpuworker and use him. if none idle, queue task onto
  * the pending onion list and return.
@@ -360,6 +388,9 @@
 
   tor_assert(question_type == CPUWORKER_TASK_ONION);
 
+  cull_wedged_cpuworkers();
+  spawn_enough_cpuworkers();
+
   if (question_type == CPUWORKER_TASK_ONION) {
     circ = task;
 



More information about the tor-commits mailing list