Skip to content

Commit

Permalink
Fix off-by-one error in promote_to_ready (#41)
Browse files Browse the repository at this point in the history
The `..` syntax creates a _half-open_ range (see https://doc.rust-lang.org/std/ops/struct.Range.html), so all that messing about with `n-1` in #39 and #40 was never actually necessary. This actually fixes the Conduit test I mentioned in #39 (comment); it no longer hangs.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Jan 26, 2018
1 parent 251509a commit c132a99
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tower-balance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,27 @@ where
debug!("promoting to ready: {}", n);
// Iterate through the not-ready endpoints from right to left to prevent removals
// from reordering services in a way that could prevent a service from being polled.
for idx in (0..n-1).rev() {
for idx in (0..n).rev() {
let is_ready = {
let (_, svc) = self.not_ready
.get_index_mut(idx)
.expect("invalid not_ready index");;
svc.poll_ready().map_err(Error::Inner)?.is_ready()
};

trace!("not_ready[{:?}]: is_ready={:?};", idx, is_ready);
if is_ready {
debug!("promoting to ready");
debug!("not_ready[{:?}]: promoting to ready", idx);
let (key, svc) = self.not_ready
.swap_remove_index(idx)
.expect("invalid not_ready index");
self.ready.insert(key, svc);
} else {
debug!("not promoting to ready");
debug!("not_ready[{:?}]: not promoting to ready", idx);
}
}

debug!("promoting to ready: done");

Ok(())
}

Expand Down

0 comments on commit c132a99

Please sign in to comment.