Browse Source

sched: Use the sched_heap_idx field to double-check our fix for 24700.

Signed-off-by: David Goulet <dgoulet@torproject.org>
Nick Mathewson 6 years ago
parent
commit
cb5654f300
3 changed files with 25 additions and 11 deletions
  1. 3 0
      src/or/channel.c
  2. 12 8
      src/or/scheduler.c
  3. 10 3
      src/or/scheduler_kist.c

+ 3 - 0
src/or/channel.c

@@ -951,6 +951,9 @@ channel_init(channel_t *chan)
 
   /* Scheduler state is idle */
   chan->scheduler_state = SCHED_CHAN_IDLE;
+
+  /* Channel is not in the scheduler heap. */
+  chan->sched_heap_idx = -1;
 }
 
 /**

+ 12 - 8
src/or/scheduler.c

@@ -538,10 +538,12 @@ scheduler_channel_has_waiting_cells,(channel_t *chan))
      * channels_pending.
      */
     chan->scheduler_state = SCHED_CHAN_PENDING;
-    smartlist_pqueue_add(channels_pending,
-                         scheduler_compare_channels,
-                         offsetof(channel_t, sched_heap_idx),
-                         chan);
+    if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+      smartlist_pqueue_add(channels_pending,
+                           scheduler_compare_channels,
+                           offsetof(channel_t, sched_heap_idx),
+                           chan);
+    }
     log_debug(LD_SCHED,
               "Channel " U64_FORMAT " at %p went from waiting_for_cells "
               "to pending",
@@ -665,10 +667,12 @@ scheduler_channel_wants_writes(channel_t *chan)
      */
     log_debug(LD_SCHED, "chan=%" PRIu64 " became pending",
         chan->global_identifier);
-    smartlist_pqueue_add(channels_pending,
-                         scheduler_compare_channels,
-                         offsetof(channel_t, sched_heap_idx),
-                         chan);
+    if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+      smartlist_pqueue_add(channels_pending,
+                           scheduler_compare_channels,
+                           offsetof(channel_t, sched_heap_idx),
+                           chan);
+    }
     chan->scheduler_state = SCHED_CHAN_PENDING;
     log_debug(LD_SCHED,
               "Channel " U64_FORMAT " at %p went from waiting_to_write "

+ 10 - 3
src/or/scheduler_kist.c

@@ -704,8 +704,10 @@ kist_scheduler_run(void)
       /* Case 4: cells to send, and still open for writes */
 
       chan->scheduler_state = SCHED_CHAN_PENDING;
-      smartlist_pqueue_add(cp, scheduler_compare_channels,
-                           offsetof(channel_t, sched_heap_idx), chan);
+      if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+        smartlist_pqueue_add(cp, scheduler_compare_channels,
+                             offsetof(channel_t, sched_heap_idx), chan);
+      }
     }
   } /* End of main scheduling loop */
 
@@ -725,8 +727,13 @@ kist_scheduler_run(void)
     SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) {
       readd_chan->scheduler_state = SCHED_CHAN_PENDING;
       if (!smartlist_contains(cp, readd_chan)) {
-        smartlist_pqueue_add(cp, scheduler_compare_channels,
+        if (!SCHED_BUG(chan->sched_heap_idx != -1, chan)) {
+          /* XXXX Note that the check above is in theory redundant with
+           * the smartlist_contains check.  But let's make sure we're
+           * not messing anything up, and leave them both for now. */
+          smartlist_pqueue_add(cp, scheduler_compare_channels,
                              offsetof(channel_t, sched_heap_idx), readd_chan);
+        }
       }
     } SMARTLIST_FOREACH_END(readd_chan);
     smartlist_free(to_readd);