From b8f1f0ccf168fa5eb3ff21cc4e64f170f0b05ec3 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 31 May 2019 14:27:46 -0700 Subject: [PATCH] Prevent trying to assign capacity to streams that were just reset --- src/proto/streams/prioritize.rs | 21 +++++++++++++++++---- tests/h2-support/src/prelude.rs | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/proto/streams/prioritize.rs b/src/proto/streams/prioritize.rs index 6e509b1..88f1bca 100644 --- a/src/proto/streams/prioritize.rs +++ b/src/proto/streams/prioritize.rs @@ -352,6 +352,14 @@ impl Prioritize { None => return, }; + // Streams pending capacity may have been reset before capacity + // became available. In that case, the stream won't want any + // capacity, and so we shouldn't "transition" on it, but just evict + // it and continue the loop. + if !(stream.state.is_send_streaming() || stream.buffered_send_data > 0) { + continue; + } + counts.transition(stream, |_, mut stream| { // Try to assign capacity to the stream. This will also re-queue the // stream if there isn't enough connection level capacity to fulfill @@ -378,7 +386,8 @@ impl Prioritize { ); trace!( - "try_assign_capacity; requested={}; additional={}; buffered={}; window={}; conn={}", + "try_assign_capacity; stream={:?}, requested={}; additional={}; buffered={}; window={}; conn={}", + stream.id, total_requested, additional, stream.buffered_send_data, @@ -409,7 +418,11 @@ impl Prioritize { // TODO: Should prioritization factor into this? let assign = cmp::min(conn_available, additional); - trace!(" assigning; num={}", assign); + trace!( + " assigning; stream={:?}, capacity={}", + stream.id, + assign, + ); // Assign the capacity to the stream stream.assign_capacity(assign); @@ -419,7 +432,7 @@ impl Prioritize { } trace!( - "try_assign_capacity; available={}; requested={}; buffered={}; has_unavailable={:?}", + "try_assign_capacity(2); available={}; requested={}; buffered={}; has_unavailable={:?}", stream.send_flow.available(), stream.requested_send_capacity, stream.buffered_send_data, @@ -604,7 +617,7 @@ impl Prioritize { } pub fn clear_queue(&mut self, buffer: &mut Buffer>, stream: &mut store::Ptr) { - trace!("clear_queue; stream-id={:?}", stream.id); + trace!("clear_queue; stream={:?}", stream.id); // TODO: make this more efficient? while let Some(frame) = stream.pending_send.pop_front(buffer) { diff --git a/tests/h2-support/src/prelude.rs b/tests/h2-support/src/prelude.rs index 39967d3..993b2e1 100644 --- a/tests/h2-support/src/prelude.rs +++ b/tests/h2-support/src/prelude.rs @@ -70,7 +70,7 @@ where B: IntoBuf + 'static, { fn run(&mut self, f: F) -> Result { - use futures::future::{self, Future}; + use futures::future; use futures::future::Either::*; let res = future::poll_fn(|| self.poll()).select2(f).wait();