From 69bcd164ee9ae181973efbaba8a68e7066defd81 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sun, 18 Mar 2018 14:57:55 +0100 Subject: [PATCH] Split big assert statement into decision tree with explanations --- src/or/connection.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/or/connection.c b/src/or/connection.c index 5532551cfe0..ee08dcf8ca3 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -5093,15 +5093,29 @@ assert_connection_ok(connection_t *conn, time_t now) tor_assert(!SOCKET_OK(conn->s)); if (conn->outbuf_flushlen > 0) { - /* With optimistic data, we may have queued data in - * EXIT_CONN_STATE_RESOLVING while the conn is not yet marked to writing. - * */ - tor_assert((conn->type == CONN_TYPE_EXIT && - conn->state == EXIT_CONN_STATE_RESOLVING) || - connection_is_writing(conn) || - conn->write_blocked_on_bw || - (CONN_IS_EDGE(conn) && - TO_EDGE_CONN(conn)->edge_blocked_on_circ)); + if (CONN_IS_EDGE(conn)) { + if (conn->type == CONN_TYPE_EXIT) { + /* With optimistic data, we may have queued data in + * EXIT_CONN_STATE_RESOLVING while the conn is not yet marked to + * writing. + * */ + if (conn->state != EXIT_CONN_STATE_RESOLVING) { + tor_assertf(connection_is_writing(conn) || conn->write_blocked_on_bw, + "Exit connection %llu is neither resolving, " + "inor writing out t's nonempty outbuf", + conn->global_identifier); + } + } else if (TO_EDGE_CONN(conn)->edge_blocked_on_circ == 0) { + tor_assertf(connection_is_writing(conn) || conn->write_blocked_on_bw, + "Edge connection %llu is neither blocked nor " + "writing out it's nonempty outbuf.", + conn->global_identifier); + } + } else { + tor_assertf(connection_is_writing(conn) || conn->write_blocked_on_bw, + "Connection %llu is not writing out it's nonempty outbuf", + conn->global_identifier); + } } if (conn->hold_open_until_flushed)