Skip to content

Commit

Permalink
Fix more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 12, 2024
1 parent cff1f99 commit 0a04234
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
30 changes: 17 additions & 13 deletions crates/fluke/src/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,8 @@ impl<D: ServerDriver + 'static, W: WriteOwned> ServerContext<D, W> {
) -> Result<(), H2ConnectionError> {
loop {
tokio::select! {
ev = self.ev_rx.recv() => {
match ev {
Some(ev) => self.handle_event(ev).await?,
None => unreachable!("the context owns a copy of the sender, and this method has &mut self, so the sender can't be dropped while this method is running"),
}
},
biased;

maybe_frame = rx.recv() => {
if let Some((frame, payload)) = maybe_frame {
self.process_frame(frame, payload, &mut rx).await?;
Expand All @@ -354,6 +350,13 @@ impl<D: ServerDriver + 'static, W: WriteOwned> ServerContext<D, W> {
break;
}
}

ev = self.ev_rx.recv() => {
match ev {
Some(ev) => self.handle_event(ev).await?,
None => unreachable!("the context owns a copy of the sender, and this method has &mut self, so the sender can't be dropped while this method is running"),
}
},
}
}

Expand Down Expand Up @@ -557,14 +560,15 @@ impl<D: ServerDriver + 'static, W: WriteOwned> ServerContext<D, W> {
return Err(H2ConnectionError::ClientSidShouldBeOdd);
}

if frame.stream_id <= self.state.last_stream_id {
debug!(
frame_stream_id = %frame.stream_id,
last_stream_id = %self.state.last_stream_id,
"Received headers for invalid stream ID"
if frame.stream_id < self.state.last_stream_id {
// we're going back? we can't.
return Err(
H2ConnectionError::ClientSidShouldBeNumericallyIncreasing {
stream_id: frame.stream_id,
last_stream_id: self.state.last_stream_id,
},
);

// this stream may have existed, but it no longer does:
} else if frame.stream_id == self.state.last_stream_id {
return Err(H2ConnectionError::StreamClosed {
stream_id: frame.stream_id,
});
Expand Down
6 changes: 6 additions & 0 deletions crates/fluke/src/h2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ pub(crate) enum H2ConnectionError {
#[error("client tried to initiate an even-numbered stream")]
ClientSidShouldBeOdd,

#[error("client stream IDs should be numerically increasing")]
ClientSidShouldBeNumericallyIncreasing {
stream_id: StreamId,
last_stream_id: StreamId,
},

#[error("received {frame_type:?} frame with Padded flag but empty payload")]
PaddedFrameEmpty { frame_type: FrameType },

Expand Down

0 comments on commit 0a04234

Please sign in to comment.