diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-11-02 10:32:18 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-11-02 10:32:18 -0400 |
commit | 65d22dc2f2262dfb0066bff12a0df2db97ca560b (patch) | |
tree | a25a26ce5c124b02f0b1723b029b42a99ae6dba8 /src/or/scheduler.c | |
parent | f865993653604d7e3e8256d052398591627f8989 (diff) | |
parent | cb42c62c9e87d4699add69087ba25d1454758bb0 (diff) | |
download | tor-65d22dc2f2262dfb0066bff12a0df2db97ca560b.tar.gz tor-65d22dc2f2262dfb0066bff12a0df2db97ca560b.zip |
Merge branch 'maint-0.3.2'
Diffstat (limited to 'src/or/scheduler.c')
-rw-r--r-- | src/or/scheduler.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/or/scheduler.c b/src/or/scheduler.c index 3ac3f406af..ef743bbc38 100644 --- a/src/or/scheduler.c +++ b/src/or/scheduler.c @@ -9,6 +9,9 @@ #define SCHEDULER_KIST_PRIVATE #include "scheduler.h" #include "main.h" +#include "buffers.h" +#define TOR_CHANNEL_INTERNAL_ +#include "channeltls.h" #include <event2/event.h> @@ -604,7 +607,7 @@ scheduler_release_channel,(channel_t *chan)) } if (chan->scheduler_state == SCHED_CHAN_PENDING) { - if (smartlist_pos(channels_pending, chan) == -1) { + if (SCHED_BUG(smartlist_pos(channels_pending, chan) == -1, chan)) { log_warn(LD_SCHED, "Scheduler asked to release channel %" PRIu64 " " "but it wasn't in channels_pending", chan->global_identifier); @@ -667,6 +670,43 @@ scheduler_channel_wants_writes(channel_t *chan) } } +/* Log warn the given channel and extra scheduler context as well. This is + * used by SCHED_BUG() in order to be able to extract as much information as + * we can when we hit a bug. Channel chan can be NULL. */ +void +scheduler_bug_occurred(const channel_t *chan) +{ + char buf[128]; + + if (chan != NULL) { + const size_t outbuf_len = + buf_datalen(TO_CONN(BASE_CHAN_TO_TLS((channel_t *) chan)->conn)->outbuf); + tor_snprintf(buf, sizeof(buf), + "Channel %" PRIu64 " in state %s and scheduler state %d." + " Num cells on cmux: %d. Connection outbuf len: %lu.", + chan->global_identifier, + channel_state_to_string(chan->state), + chan->scheduler_state, circuitmux_num_cells(chan->cmux), + outbuf_len); + } + + { + char *msg; + /* Rate limit every 60 seconds. If we start seeing this every 60 sec, we + * know something is stuck/wrong. It *should* be loud but not too much. */ + static ratelim_t rlimit = RATELIM_INIT(60); + if ((msg = rate_limit_log(&rlimit, approx_time()))) { + log_warn(LD_BUG, "%s Num pending channels: %d. " + "Channel in pending list: %s.%s", + (chan != NULL) ? buf : "No channel in bug context.", + smartlist_len(channels_pending), + (smartlist_pos(channels_pending, chan) == -1) ? "no" : "yes", + msg); + tor_free(msg); + } + } +} + #ifdef TOR_UNIT_TESTS /* |