Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/proto/streams/counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,16 @@ impl Counts {
where
F: FnOnce(&mut Self, &mut store::Ptr) -> U,
{
// TODO: Does this need to be computed before performing the action?
let is_pending_reset = stream.is_pending_reset_expiration();

// Run the action
let ret = f(self, &mut stream);

self.transition_after(stream, is_pending_reset);
self.transition_after(stream);

ret
}

// TODO: move this to macro?
pub fn transition_after(&mut self, mut stream: store::Ptr, is_reset_counted: bool) {
pub fn transition_after(&mut self, mut stream: store::Ptr) {
tracing::trace!(
"transition_after; stream={:?}; state={:?}; is_closed={:?}; \
pending_send_empty={:?}; buffered_send_data={}; \
Expand All @@ -311,9 +308,6 @@ impl Counts {
if stream.is_closed() {
if !stream.is_pending_reset_expiration() {
stream.unlink();
if is_reset_counted {
self.dec_num_reset_streams();
}
}

if !stream.state.is_scheduled_reset() && stream.is_counted {
Expand Down Expand Up @@ -355,7 +349,7 @@ impl Counts {
}
}

fn dec_num_reset_streams(&mut self) {
pub fn dec_num_reset_streams(&mut self) {
assert!(self.num_local_reset_streams > 0);
self.num_local_reset_streams -= 1;
}
Expand Down
19 changes: 5 additions & 14 deletions src/proto/streams/prioritize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,18 +685,16 @@ impl Prioritize {

pub fn clear_pending_send(&mut self, store: &mut Store, counts: &mut Counts) {
while let Some(mut stream) = self.pending_send.pop(store) {
let is_pending_reset = stream.is_pending_reset_expiration();
if let Some(reason) = stream.state.get_scheduled_reset() {
stream.set_reset(reason, Initiator::Library);
}
counts.transition_after(stream, is_pending_reset);
counts.transition_after(stream);
}
}

pub fn clear_pending_open(&mut self, store: &mut Store, counts: &mut Counts) {
while let Some(stream) = self.pending_open.pop(store) {
let is_pending_reset = stream.is_pending_reset_expiration();
counts.transition_after(stream, is_pending_reset);
counts.transition_after(stream);
}
}

Expand All @@ -718,14 +716,7 @@ impl Prioritize {
let span = tracing::trace_span!("popped", ?stream.id, ?stream.state);
let _e = span.enter();

// It's possible that this stream, besides having data to send,
// is also queued to send a reset, and thus is already in the queue
// to wait for "some time" after a reset.
//
// To be safe, we just always ask the stream.
let is_pending_reset = stream.is_pending_reset_expiration();

tracing::trace!(is_pending_reset);
tracing::trace!(is_pending_reset = stream.is_pending_reset_expiration());

let frame = match stream.pending_send.pop_front(buffer) {
Some(Frame::Data(mut frame)) => {
Expand Down Expand Up @@ -873,7 +864,7 @@ impl Prioritize {
// Since this should only happen as a consequence of `clear_queue`,
// we must be in a closed state of some kind.
debug_assert!(stream.state.is_closed());
counts.transition_after(stream, is_pending_reset);
counts.transition_after(stream);
continue;
}
}
Expand All @@ -894,7 +885,7 @@ impl Prioritize {
self.pending_send.push(&mut stream);
}

counts.transition_after(stream, is_pending_reset);
counts.transition_after(stream);

return Some(frame);
}
Expand Down
31 changes: 19 additions & 12 deletions src/proto/streams/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,16 +1043,21 @@ impl Recv {
return;
}

if counts.can_inc_num_reset_streams() {
counts.inc_num_reset_streams();
tracing::trace!("enqueue_reset_expiration; added {:?}", stream.id);
self.pending_reset_expired.push(stream);
} else {
tracing::trace!(
"enqueue_reset_expiration; dropped {:?}, over max_concurrent_reset_streams",
stream.id
);
if !counts.can_inc_num_reset_streams() {
let oldest = match self.pending_reset_expired.pop(stream) {
Some(oldest) => oldest,
// Retention is disabled.
None => return,
};
tracing::trace!("enqueue_reset_expiration; evicted {:?}", oldest.id);
// Free the queue slot even if the stream still has frames to send.
counts.dec_num_reset_streams();
counts.transition_after(oldest);
}

counts.inc_num_reset_streams();
tracing::trace!("enqueue_reset_expiration; added {:?}", stream.id);
self.pending_reset_expired.push(stream);
}

pub fn clear_expired_reset_streams(&mut self, store: &mut Store, counts: &mut Counts) {
Expand All @@ -1066,7 +1071,8 @@ impl Recv {
// monotonic). We use a saturating operation to avoid this panic here.
now.saturating_duration_since(reset_at) > reset_duration
}) {
counts.transition_after(stream, true);
counts.dec_num_reset_streams();
counts.transition_after(stream);
}
}
}
Expand Down Expand Up @@ -1096,13 +1102,14 @@ impl Recv {
/// Called on EOF
fn clear_all_reset_streams(&mut self, store: &mut Store, counts: &mut Counts) {
while let Some(stream) = self.pending_reset_expired.pop(store) {
counts.transition_after(stream, true);
counts.dec_num_reset_streams();
counts.transition_after(stream);
}
}

fn clear_all_pending_accept(&mut self, store: &mut Store, counts: &mut Counts) {
while let Some(stream) = self.pending_accept.pop(store) {
counts.transition_after(stream, false);
counts.transition_after(stream);
}
}

Expand Down
13 changes: 5 additions & 8 deletions tests/h2-tests/tests/stream_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,15 +1059,12 @@ async fn rst_stream_max() {
srv.send_frame(frames::data(3, vec![0; 16])).await;
srv.recv_frame(frames::reset(1).cancel()).await;
srv.recv_frame(frames::reset(3).cancel()).await;
// sending frame after canceled!
// olders streams trump newer streams
// 1 is still being ignored
srv.send_frame(frames::data(1, vec![0; 16]).eos()).await;
// ping pong to be sure of no goaway
srv.ping_pong([1; 8]).await;
// 3 has been evicted, will get a reset
// The most recently reset stream still has its grace period.
srv.send_frame(frames::data(3, vec![0; 16]).eos()).await;
srv.recv_frame(frames::reset(3).stream_closed()).await;
srv.ping_pong([1; 8]).await;
// The oldest reset stream has lost its grace period.
srv.send_frame(frames::data(1, vec![0; 16]).eos()).await;
srv.recv_frame(frames::reset(1).stream_closed()).await;
};

let client = async move {
Expand Down