conn: Close the read side of a closing connection when write limit is reached

In conn_close_if_marked(), we can decide to keep a connection open that still
has data to flush on the wire if it is being rate limited on the write side.

However, in this process, we were also looking at the read() side which can
still have token in its bucket and thus not stop the reading. This lead to a
BUG() introduced in 0.3.4.1-alpha that was expecting the read side to be
closed due to the rate limit but which only applies on the write side.

This commit removes any bandwidth check on the read side and simply stop the
read side on the connection regardless of the bucket state. If we keep the
connection open to flush it out before close, we should not read anything.

Fixes #27750

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2018-11-13 10:22:10 -05:00 committed by Nick Mathewson
parent 42be1c668b
commit c99f220f78
2 changed files with 12 additions and 11 deletions

6
changes/bug27750 Normal file
View File

@ -0,0 +1,6 @@
o Minor bugfixes (connection, relay):
- Avoid a wrong BUG() stacktrace in case a closing connection is being held
open because the write side is rate limited but not the read side. Now,
the connection read side is simply shutdown instead of kept open until tor
is able to flush the connection and then fully close it. Fixes bug 27750;
bugfix on 0.3.4.1-alpha.

View File

@ -1036,23 +1036,18 @@ conn_close_if_marked(int i)
* busy Libevent loops where we keep ending up here and returning * busy Libevent loops where we keep ending up here and returning
* 0 until we are no longer blocked on bandwidth. * 0 until we are no longer blocked on bandwidth.
*/ */
connection_consider_empty_read_buckets(conn);
connection_consider_empty_write_buckets(conn); connection_consider_empty_write_buckets(conn);
/* Make sure that consider_empty_buckets really disabled the /* Make sure that consider_empty_buckets really disabled the
* connection: */ * connection: */
if (BUG(connection_is_writing(conn))) { if (BUG(connection_is_writing(conn))) {
connection_write_bw_exhausted(conn, true); connection_write_bw_exhausted(conn, true);
} }
if (BUG(connection_is_reading(conn))) {
/* XXXX+ We should make this code unreachable; if a connection is /* The connection is being held due to write rate limit and thus will
* marked for close and flushing, there is no point in reading to it * flush its data later. We need to stop reading because this
* at all. Further, checking at this point is a bit of a hack: it * connection is about to be closed once flushed. It should not
* would make much more sense to react in * process anything more coming in at this stage. */
* connection_handle_read_impl, or to just stop reading in connection_stop_reading(conn);
* mark_and_flush */
connection_read_bw_exhausted(conn, true/* kludge. */);
}
} }
return 0; return 0;
} }