[or-cvs] Fix a bug where you might flush some data on a tls connecti...

Roger Dingledine arma at seul.org
Fri Feb 27 04:42:16 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 main.c or.h 
Log Message:
Fix a bug where you might flush some data on a tls connection, and then
add some more data to be flushed but never turn POLLOUT on. not sure
how commonly this bug was hit, but it would be a doozy.

Also add some asserts to see if it happens elsewhere.


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- connection.c	25 Feb 2004 07:31:46 -0000	1.152
+++ connection.c	27 Feb 2004 04:42:14 -0000	1.153
@@ -506,7 +506,7 @@
   } else {
     if(flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen) < 0)
       return -1;
-      /* conns in CONNECTING state will fall through... */
+    /* conns in CONNECTING state will fall through... */
   }
 
   if(!connection_wants_to_flush(conn)) /* it's done flushing */
@@ -527,9 +527,8 @@
     return;
   }
 
-  /* XXX if linkpadding, this only applies to conns that aren't open OR connections */
   connection_start_writing(conn);
-#define MIN_TLS_FLUSHLEN 16300
+#define MIN_TLS_FLUSHLEN 15872
 /* openssl tls record size is 16383, this is close. The goal here is to
  * push data out as soon as we know there's enough for a tls record, so
  * during periods of high load we won't read the entire megabyte from
@@ -544,7 +543,11 @@
       log_fn(LOG_WARN,"flushing failed.");
     }
   }
-  conn->outbuf_flushlen += len;
+  if(len > 0) { /* if there's any left over */
+    conn->outbuf_flushlen += len;
+    connection_start_writing(conn);
+    /* because connection_handle_write() above might have stopped writing */
+  }
 }
 
 connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
@@ -758,6 +761,10 @@
   assert(conn->type >= _CONN_TYPE_MIN);
   assert(conn->type <= _CONN_TYPE_MAX);
 
+  if(conn->outbuf_flushlen > 0) {
+    assert(connection_is_writing(conn) || conn->wants_to_write);
+  }
+
   /* XXX check: wants_to_read, wants_to_write, s, poll_index,
    * marked_for_close. */
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- main.c	26 Feb 2004 22:30:44 -0000	1.171
+++ main.c	27 Feb 2004 04:42:14 -0000	1.172
@@ -136,6 +136,10 @@
   poll_array[conn->poll_index].events |= POLLIN;
 }
 
+int connection_is_writing(connection_t *conn) {
+  return poll_array[conn->poll_index].events & POLLOUT;
+}
+
 void connection_stop_writing(connection_t *conn) {
 
   assert(conn && conn->poll_index < nfds);

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.230
retrieving revision 1.231
diff -u -d -r1.230 -r1.231
--- or.h	26 Feb 2004 22:56:36 -0000	1.230
+++ or.h	27 Feb 2004 04:42:14 -0000	1.231
@@ -748,6 +748,7 @@
 int connection_is_reading(connection_t *conn);
 void connection_stop_reading(connection_t *conn);
 void connection_start_reading(connection_t *conn);
+int connection_is_writing(connection_t *conn);
 void connection_stop_writing(connection_t *conn);
 void connection_start_writing(connection_t *conn);
 



More information about the tor-commits mailing list