]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
sched: Use SCHED_BUG() macro in scheduler
authorDavid Goulet <dgoulet@torproject.org>
Tue, 3 Oct 2017 18:38:30 +0000 (14:38 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 2 Nov 2017 14:30:33 +0000 (10:30 -0400)
When a BUG() occurs, this macro will print extra information about the state
of the scheduler and the given channel if any. This will help us greatly to
fix future bugs in the scheduler especially when they occur rarely.

Fixes #23753

Signed-off-by: David Goulet <dgoulet@torproject.org>
changes/bug23753 [new file with mode: 0644]
src/or/scheduler.c
src/or/scheduler_kist.c

diff --git a/changes/bug23753 b/changes/bug23753
new file mode 100644 (file)
index 0000000..8782a8e
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor features (logging, scheduler):
+    - Introduce a SCHED_BUG() function to log extra information about the
+      scheduler state if we ever catch a bug in the scheduler. Closes ticket
+      23753.
index c656c80e9c0a3ffd36b8e409406696dfa7ae0fb7..67911ff81ebf2b70fdd37588d9b74562035e2024 100644 (file)
@@ -607,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);
index d269fb49b80b6786e52af8e1b23fa50aef0b6f9a..ea6910c7023cffb9c2284a8d261836f539631111 100644 (file)
@@ -116,7 +116,7 @@ channel_outbuf_length(channel_t *chan)
   /* In theory, this can not happen because we can not scheduler a channel
    * without a connection that has its outbuf initialized. Just in case, bug
    * on this so we can understand a bit more why it happened. */
-  if (BUG(BASE_CHAN_TO_TLS(chan)->conn == NULL)) {
+  if (SCHED_BUG(BASE_CHAN_TO_TLS(chan)->conn == NULL, chan)) {
     return 0;
   }
   return buf_datalen(TO_CONN(BASE_CHAN_TO_TLS(chan)->conn)->outbuf);
@@ -370,7 +370,7 @@ socket_can_write(socket_table_t *table, const channel_t *chan)
 {
   socket_table_ent_t *ent = NULL;
   ent = socket_table_search(table, chan);
-  IF_BUG_ONCE(!ent) {
+  if (SCHED_BUG(!ent, chan)) {
     return 1; // Just return true, saying that kist wouldn't limit the socket
   }
 
@@ -390,7 +390,7 @@ update_socket_info(socket_table_t *table, const channel_t *chan)
 {
   socket_table_ent_t *ent = NULL;
   ent = socket_table_search(table, chan);
-  IF_BUG_ONCE(!ent) {
+  if (SCHED_BUG(!ent, chan)) {
     return; // Whelp. Entry didn't exist for some reason so nothing to do.
   }
   update_socket_info_impl(ent);
@@ -402,7 +402,7 @@ update_socket_written(socket_table_t *table, channel_t *chan, size_t bytes)
 {
   socket_table_ent_t *ent = NULL;
   ent = socket_table_search(table, chan);
-  IF_BUG_ONCE(!ent) {
+  if (SCHED_BUG(!ent, chan)) {
     return; // Whelp. Entry didn't exist so nothing to do.
   }