[or-cvs] Fix the dns bug: children weren"t dying

Roger Dingledine arma at seul.org
Tue Jan 6 07:53:42 UTC 2004


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

Modified Files:
	connection.c cpuworker.c dns.c or.h 
Log Message:
Fix the dns bug: children weren't dying

We were telling a child to die by closing the parent's file descriptor
to him. But newer children were inheriting the open file descriptor from
the parent, and since they weren't closing them, the socket never closed,
so the child never read eof, so he never knew to exit.

As a side effect to this bug, we were probably failing to properly close
connections to remote hosts, ORs, and OPs, after a dns child was born.

I'm surprised Tor worked at all.


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- connection.c	28 Dec 2003 04:46:09 -0000	1.145
+++ connection.c	6 Jan 2004 07:53:40 -0000	1.146
@@ -128,6 +128,15 @@
   free(conn);
 }
 
+void connection_free_all(void) {
+  int i, n;
+  connection_t **carray;
+
+  get_connection_array(&carray,&n);
+  for(i=0;i<n;i++)
+    connection_free(carray[i]);
+}
+
 int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
   struct sockaddr_in bindaddr; /* where to bind */
   struct hostent *rent;

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cpuworker.c	19 Dec 2003 19:55:02 -0000	1.19
+++ cpuworker.c	6 Jan 2004 07:53:40 -0000	1.20
@@ -126,6 +126,7 @@
 
   close(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
+  connection_free_all(); /* so the child doesn't hold the parent's fd's open */
 
   for(;;) {
 

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- dns.c	17 Dec 2003 09:20:29 -0000	1.46
+++ dns.c	6 Jan 2004 07:53:40 -0000	1.47
@@ -395,6 +395,7 @@
 
   close(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
+  connection_free_all(); /* so the child doesn't hold the parent's fd's open */
 
   for(;;) {
 
@@ -506,7 +507,7 @@
     num_dnsworkers++;
   }
 
-  while(num_dnsworkers > num_dnsworkers_needed+MAX_IDLE_DNSWORKERS) { /* too many idle? */
+  while(num_dnsworkers > num_dnsworkers_busy+MAX_IDLE_DNSWORKERS) { /* too many idle? */
     /* cull excess workers */
     log_fn(LOG_WARN,"%d of %d dnsworkers are idle. Killing one.",
            num_dnsworkers-num_dnsworkers_needed, num_dnsworkers);

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.217
retrieving revision 1.218
diff -u -d -r1.217 -r1.218
--- or.h	5 Jan 2004 05:23:03 -0000	1.217
+++ or.h	6 Jan 2004 07:53:40 -0000	1.218
@@ -615,6 +615,7 @@
 
 connection_t *connection_new(int type);
 void connection_free(connection_t *conn);
+void connection_free_all(void);
 
 int connection_create_listener(char *bindaddress, uint16_t bindport, int type);
 



More information about the tor-commits mailing list