diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-03-14 12:53:57 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-03-14 12:53:57 -0400 |
commit | a64be7eaa9add3ac147447faae77906bbafd1b0a (patch) | |
tree | 8f7a4aa011f042f324e2c02becf1113e0057e31d /src/or | |
parent | d8b93b31a044be12778f9d7dcd9e4dd666db85e0 (diff) | |
parent | 307b863556e34f0f1575c8c7ea1dd79e07eff16c (diff) | |
download | tor-a64be7eaa9add3ac147447faae77906bbafd1b0a.tar.gz tor-a64be7eaa9add3ac147447faae77906bbafd1b0a.zip |
Merge remote-tracking branch 'public/bug16248_027'
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/main.c | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/src/or/main.c b/src/or/main.c index d84e365122..cfd11696ec 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -543,6 +543,45 @@ connection_is_reading(connection_t *conn) (conn->read_event && event_pending(conn->read_event, EV_READ, NULL)); } +/** Check whether <b>conn</b> is correct in having (or not having) a + * read/write event (passed in <b>ev</b). On success, return 0. On failure, + * log a warning and return -1. */ +static int +connection_check_event(connection_t *conn, struct event *ev) +{ + int bad; + + if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) { + /* DNS requests which we launch through the dnsserv.c module do not have + * any underlying socket or any underlying linked connection, so they + * shouldn't have any attached events either. + */ + bad = ev != NULL; + } else { + /* Everytyhing else should have an underlying socket, or a linked + * connection (which is also tracked with a read_event/write_event pair). + */ + bad = ev == NULL; + } + + if (bad) { + log_warn(LD_BUG, "Event missing on connection %p [%s;%s]. " + "socket=%d. linked=%d. " + "is_dns_request=%d. Marked_for_close=%s:%d", + conn, + conn_type_to_string(conn->type), + conn_state_to_string(conn->type, conn->state), + (int)conn->s, (int)conn->linked, + (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request), + conn->marked_for_close_file ? conn->marked_for_close_file : "-", + conn->marked_for_close + ); + log_backtrace(LOG_WARN, LD_BUG, "Backtrace attached."); + return -1; + } + return 0; +} + /** Tell the main loop to stop notifying <b>conn</b> of any read events. */ MOCK_IMPL(void, connection_stop_reading,(connection_t *conn)) @@ -554,7 +593,9 @@ connection_stop_reading,(connection_t *conn)) return; }); - tor_assert(conn->read_event); + if (connection_check_event(conn, conn->read_event) < 0) { + return; + } if (conn->linked) { conn->reading_from_linked_conn = 0; @@ -579,7 +620,9 @@ connection_start_reading,(connection_t *conn)) return; }); - tor_assert(conn->read_event); + if (connection_check_event(conn, conn->read_event) < 0) { + return; + } if (conn->linked) { conn->reading_from_linked_conn = 1; @@ -619,7 +662,9 @@ connection_stop_writing,(connection_t *conn)) return; }); - tor_assert(conn->write_event); + if (connection_check_event(conn, conn->write_event) < 0) { + return; + } if (conn->linked) { conn->writing_to_linked_conn = 0; @@ -645,7 +690,9 @@ connection_start_writing,(connection_t *conn)) return; }); - tor_assert(conn->write_event); + if (connection_check_event(conn, conn->write_event) < 0) { + return; + } if (conn->linked) { conn->writing_to_linked_conn = 1; |