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

[or-cvs] Add more asserts to dns-pending connections; fix a couple s...



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv16390/src/or

Modified Files:
	dns.c main.c or.h 
Log Message:
Add more asserts to dns-pending connections; fix a couple seeming bugs.

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- dns.c	21 May 2004 12:25:15 -0000	1.95
+++ dns.c	1 Jun 2004 22:09:58 -0000	1.96
@@ -103,6 +103,8 @@
  * from the cache. */
 static void purge_expired_resolves(uint32_t now) {
   struct cached_resolve *resolve;
+  struct pending_connection_t *pend;
+  connection_t *pendconn;
 
   /* this is fast because the linked list
    * oldest_cached_resolve is ordered by when they came in.
@@ -112,9 +114,21 @@
     log(LOG_DEBUG,"Forgetting old cached resolve (expires %lu)", (unsigned long)resolve->expire);
     if(resolve->state == CACHE_STATE_PENDING) {
       log_fn(LOG_WARN,"Expiring a dns resolve that's still pending. Forgot to cull it?");
-      /* XXX if resolve->pending_connections is used, then we're probably
-       * introducing bugs by closing resolve without notifying those streams.
-       */
+    }
+    if (resolve->pending_connections) {
+      log_fn(LOG_WARN, "Closing pending connections on expiring DNS resolve!");
+      while (resolve->pending_connections) {
+        pend = resolve->pending_connections;
+        resolve->pending_connections = pend->next;
+        /* Connections should only be pending if they have no socket. */
+        tor_assert(pend->conn->s == -1);
+        pendconn = pend->conn;
+        connection_edge_end(pendconn, END_STREAM_REASON_MISC,
+                            pendconn->cpath_layer);
+        connection_mark_for_close(pendconn);
+        connection_free(pendconn);
+        tor_free(pend);
+      }
     }
     oldest_cached_resolve = resolve->next;
     if(!oldest_cached_resolve) /* if there are no more, */
@@ -141,6 +155,7 @@
   struct in_addr in;
   uint32_t now = time(NULL);
   assert_connection_ok(exitconn, 0);
+  tor_assert(exitconn->s == -1);
 
   /* first check if exitconn->address is an IP. If so, we already
    * know the answer. */
@@ -213,6 +228,7 @@
   unsigned char len;
 
   tor_assert(exitconn->state == EXIT_CONN_STATE_RESOLVING);
+  tor_assert(exitconn->s == -1);
 
   spawn_enough_dnsworkers(); /* respawn here, to be sure there are enough */
 
@@ -309,6 +325,8 @@
         pend;
         pend = pend->next) {
       assert_connection_ok(pend->conn, 0);
+      tor_assert(pend->conn->s == -1);
+      tor_assert(!connection_in_array(pend->conn));
     }
   }
 }
@@ -343,10 +361,12 @@
     pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
     pendconn = pend->conn; /* don't pass complex things to the
                               connection_mark_for_close macro */
+    tor_assert(pendconn->s == -1);
     if(!pendconn->marked_for_close) {
       connection_edge_end(pendconn, END_STREAM_REASON_MISC, pendconn->cpath_layer);
       connection_mark_for_close(pendconn);
     }
+    connection_free(pendconn);
     resolve->pending_connections = pend->next;
     tor_free(pend);
   }
@@ -430,7 +450,6 @@
     assert_connection_ok(pend->conn,time(NULL));
     pend->conn->addr = resolve->addr;
 
-
     if(resolve->state == CACHE_STATE_FAILED) {
       pendconn = pend->conn; /* don't pass complex things to the
                                 connection_mark_for_close macro */

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.278
retrieving revision 1.279
diff -u -d -r1.278 -r1.279
--- main.c	1 Jun 2004 17:31:13 -0000	1.278
+++ main.c	1 Jun 2004 22:09:58 -0000	1.279
@@ -127,6 +127,16 @@
   return 0;
 }
 
+/** Return true iff conn is in the current poll array. */
+int connection_in_array(connection_t *conn) {
+  int i;
+  for (i=0; i<nfds; ++i) {
+    if (conn==connection_array[i])
+      return 1;
+  }
+  return 0;
+}
+
 /** Set <b>*array</b> to an array of all connections, and <b>*n</b>
  * to the length of the array. <b>*array</b> and <b>*n</b> must not
  * be modified.

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.360
retrieving revision 1.361
diff -u -d -r1.360 -r1.361
--- or.h	1 Jun 2004 18:19:01 -0000	1.360
+++ or.h	1 Jun 2004 22:09:58 -0000	1.361
@@ -1125,6 +1125,7 @@
 
 int connection_add(connection_t *conn);
 int connection_remove(connection_t *conn);
+int connection_in_array(connection_t *conn);
 
 void get_connection_array(connection_t ***array, int *n);